Swift3 - 无法以编程方式找到UISegmentedControl

时间:2017-06-14 17:52:09

标签: swift3 uisegmentedcontrol cgrect

我有一个可以使用此代码轻松找到的按钮:

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)

    )
)

1 个答案:

答案 0 :(得分:0)

感谢菲利普米尔斯,这个是有效的

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))