Geometry 是 UIView 和 CGRect 扩展,添加了属性来进行更高效的操作:
top
left
bottom
right
width
height
centerX
centerY
center
myView.frame = CGRectMake(10, 10, 20, 20) myView.left = 20 // Frame is now {{20, 10}, {20, 20}} myView.width = 100 // Frame is now {{20, 10}, {100, 20}} myView.right = 150 // Frame is now {{50, 10}, {100, 20}}
同时也提供 StringLiteralConverters 给 CGRect 和 CGPoint,所以你可以用 Strings 来初始化 CGRect:
myView.frame = "10, 10, 20, 20" myView.center = "50, 50" CGRect rect = "20, 25, 100, 100"