我很难在UIButton
上添加左填充.我有UIButton
和UIControlContentHorizontalAlignmentLeft
.我希望文本显示在左侧,但它太左了.当我给出边界时,它看起来不太好.我想给一些填充关于5px的文本,比如CSS.我在谷歌上搜索了解决方案,但没有找到一个特别适合UIButton
人的解决方案.
我很难在UIButton
上添加左填充.我有UIButton
和UIControlContentHorizontalAlignmentLeft
.我希望文本显示在左侧,但它太左了.当我给出边界时,它看起来不太好.我想给一些填充关于5px的文本,比如CSS.我在谷歌上搜索了解决方案,但没有找到一个特别适合UIButton
人的解决方案.
titleEdgeInsets边缘的插入页边距或起始页边距
@属性(非原子)指导的插入集标题插入集
Discussion.用这个
Availability在iOS 2.0及更高版本中可用.
在UIButton中声明.H
试试看:)
[myButton setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 5.0, 0.0, 0.0)];
此外,如果您使用的是自定义按钮,则有内容插入和图像插入.
万一你来找Swift .这是有效的Swift 3.0?
myButton.titleEdgeInsets = UIEdgeInsets(top: 0.0, left: 5.0, bottom: 0.0, right: 0.0)
你也可以直接设置.如果想要使用一个或两个属性,这是很有用的.
myButton.titleEdgeInsets.top = 0
myButton.titleEdgeInsets.left = 5
myButton.titleEdgeInsets.bottom = 0
myButton.titleEdgeInsets.right = 0