我在 UIView
中有一个 UIButton
,我的 UIButton
有我在 Storyboard中设置的约束。现在,我想将 UIButton
的中心设置在 UIView
的中心。我将如何以编程方式执行此操作?
最佳答案
尝试像 .center
属性
myButton.center = self.view.center
如果需要,您还可以指定 x
和 y
。
myButton.center.x = self.view.center.x // for horizontal
myButton.center.y = self.view.center.y // for vertical
关于ios - 以编程方式设置 UIButton 的中心 - SWIFT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32219161/