ios - 以编程方式设置 UIButton 的中心 - SWIFT

标签 ios swift uiview uibutton

我在 UIView 中有一个 UIButton,我的 UIButton 有我在 Storyboard中设置的约束。现在,我想将 UIButton 的中心设置在 UIView 的中心。我将如何以编程方式执行此操作?

最佳答案

尝试像 .center 属性

myButton.center = self.view.center

如果需要,您还可以指定 xy

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/

相关文章:

swift - 如何在 swift 中使用谓词?

ios - 如何在导航栏上使用图像 Logo 而不是标题

ios - 使 UIView 和 UICollectionView 一起滚动

iphone - 获取自定义 UIView 子类以跟随 UIControl

ios - iPad 显示为纵向,但认为它是横向

ios - UICollectionView 单元格与屏幕对齐吗?

ios - 将 NSData 字节顺序更改为小端

ios - 仅在 x 轴上移动 Sprite

android - Paypal Android SDK 是否支持并行、链式支付?

iphone - 为 UITableView 设置三边边框 - IOS