【发布时间】:2017-06-14 17:52:09
【问题描述】:
我有一个按钮,我可以使用以下代码轻松找到它:
let btnRewind = UIButton(
frame:CGRect(
x:(UIScreen.main.bounds.size.height/2 - 4*UIScreen.main.bounds.size.height/30),
y:(UIScreen.main.bounds.size.width/2 - UIScreen.main.bounds.size.height/30),
width:(UIScreen.main.bounds.size.height/15),
height:(UIScreen.main.bounds.size.height/15)
)
)
但相同的代码不适用于我的 UISegmentedControl。那是x:0 y:0。我错过了什么:/
var sgmSpeed = UISegmentedControl(
frame:CGRect(
x:(UIScreen.main.bounds.size.height/2 - UIScreen.main.bounds.size.height/30),
y:(UIScreen.main.bounds.size.width/2 - UIScreen.main.bounds.size.height/30),
width:(UIScreen.main.bounds.size.height/15),
height:(UIScreen.main.bounds.size.width/15)
)
)
【问题讨论】:
-
尝试使用
initWithItems构造函数。文档说,“自动调整大小以适应其内容”。
标签: swift3 uisegmentedcontrol cgrect