Swift3 - 无法以编程方式定位 UISegmentedControl
Swift3 - cannot locate UISegmentedControl programmatically
我有一个按钮,我可以使用以下代码轻松找到它:
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)
)
)
感谢 Philip Mills
sgmSpeed.frame = CGRect.init(x:(UIScreen.main.bounds.size.height/2 - UIScreen.main.bounds.size.height/6),
y:(UIScreen.main.bounds.size.width/2 + UIScreen.main.bounds.size.height/15),
width:(UIScreen.main.bounds.size.height/3),
height:(UIScreen.main.bounds.size.width/15))
我有一个按钮,我可以使用以下代码轻松找到它:
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)
)
)
感谢 Philip Mills
sgmSpeed.frame = CGRect.init(x:(UIScreen.main.bounds.size.height/2 - UIScreen.main.bounds.size.height/6),
y:(UIScreen.main.bounds.size.width/2 + UIScreen.main.bounds.size.height/15),
width:(UIScreen.main.bounds.size.height/3),
height:(UIScreen.main.bounds.size.width/15))