我无法以 IB 为中心设置 UIButton 的标题。我的标题是多行的。
就是这样一个
但是我想要这个
我在这方面给了空间,但我不想那样做。因为在某些情况下它并没有完全对齐,我知道 UILabel 有一个属性可以设置对齐,但我不想为此编写代码.. 只想从 IB 设置所有内容。
谢谢
最佳答案
这将完全符合您的预期:
objective-C :
[myButton.titleLabel setTextAlignment:UITextAlignmentCenter];
对于 iOS 6 或更高版本是
[myButton.titleLabel setTextAlignment: NSTextAlignmentCenter];
如 tyler53's answer 中所述
swift :
myButton.titleLabel?.textAlignment = NSTextAlignment.Center
Swift 4.x 及以上版本
myButton.titleLabel?.textAlignment = .center
关于ios - 如何使 UIButton 文本对齐中心?使用 IB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5712937/