swift - 我可以在 Storyboard 上设置偏移位置吗?

标签 swift uibutton autolayout storyboard

我可以在 Storyboard 上像下面这样写代码吗?

let button = UIButton()
button.titleLabel.center = CGPoint(x:button.titleLabel.center.x, y:button.titleLabel.center.y + 30)

最佳答案

查看 UIEdgeInsets 和 UIButton 属性 titleEdgeInsets

button.titleLabelInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 30)

根据您的确切需求和代码,这应该可以满足您的需要。 (仅供引用 - 还有一个 imageEdgeInsets。)

关于swift - 我可以在 Storyboard 上设置偏移位置吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43131684/

相关文章:

ios - Swift NSURLSession 真的真的真的很慢

iphone - 将字符串分配给 UIButton 的标签值

ios - 将 3 个 UIButtons 对齐到 UIViewController 的底部中心

ios - 为什么自动布局会出现此布局问题

ios - 具有自动布局和最大尺寸保持纵横比的 UIImageView

快速访问可变长度数组

ios - 使用粒子创建特殊图形?

ios - 在两个 UIButton 图像之间淡入淡出

iphone - UIButton 自定义高亮

ios - 自定义协议(protocol)在 swift 中不起作用