当我在Objective-c中创建CGRect并且我不想设置每个值时,我以这种方式创建:
(CGRect){CGPointMake(0, 0), [UIScreen mainScreen].bounds.size}
你对swift有类似的看法吗?
答案 0 :(得分:32)
Swift为CGRect
添加了一个特殊的初始值设定项。
let rect = CGRect(
origin: CGPoint(x: 0, y: 0),
size: UIScreen.mainScreen().bounds.size
)
对于Swift 3.0,你会这样做......
let rect = CGRect(
origin: CGPoint(x: 0, y: 0),
size: UIScreen.main.bounds.size
)
答案 1 :(得分:2)
0,0
let rect = CGRect(
origin: CGPointZero,
size: UIScreen.main.bounds.size
)
答案 2 :(得分:0)
let rect = UIScreen.main.bounds