我正在尝试将按钮的标题设置在左侧。但是我尝试的所有方法都无法正常工作。
带有:
UILabelButton.titleLabel.textAlignment = .Left
要么:
UILabelButton.contentVerticalAlignment = UIControlContentVerticalAlignment // There is no left
按钮标题仍居中。
还有其他财产吗?
Answers:
使用contentHorizontalAlignment
。您必须使用UIControlContentHorizontalAlignment.Left
。您需要使用horizontal
not vertical
。
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left
斯威夫特3.x
btn.contentHorizontalAlignment = .left
样例代码
对于我的要求,我想对准左 顶部
btnAddress.contentHorizontalAlignment = UIControlContentHorizontalAlignment.left
btnAddress.contentVerticalAlignment = UIControlContentVerticalAlignment.top
btnAddress.contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.left
btnAddress.contentVerticalAlignment = UIControl.ContentVerticalAlignment.top
btnAddress.contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.left
btnAddress.contentVerticalAlignment = UIControl.ContentVerticalAlignment.top
现在,如果您希望文本从左侧开始留一些空间,请添加此
btnAddress.titleEdgeInsets = UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 0)