在Swift中更改IBOutlet的位置

时间:2014-08-25 21:42:14

标签: button swift position iboutlet

所以我有这个按钮:

@IBOutlet var bouton: UIBarButtonItem!

我想改变立场

但是buton似乎没有像SKSpriteNode那样的位置属性

有没有办法改变位置?

2 个答案:

答案 0 :(得分:16)

如果要以编程方式更改任何视图的位置,可以使用:

button.frame.origin = CGPoint(x: 10, y: 10)

答案 1 :(得分:1)

如果您使用自动布局,则无法使用myButton.frame.origin设置按钮。所以你必须添加约束。例如:

let buttonConstraintY = NSLayoutConstraint(item: youButton, attribute: NSLayoutAttribute.centerY, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 10) self.view.addConstraint(buttonConstraintY)