设置最小字体大小的UIButton保证金
问题描述:
我已经找到解决方案如何设置最小字体大小将对应于我的按钮的宽度:设置最小字体大小的UIButton保证金
button.titleLabel.numberOfLines = 1;
button.titleLabel.adjustsFontSizeToFitWidth = YES;
button.titleLabel.lineBreakMode = NSLineBreakByClipping;
但我怎么能增加保证金的左侧和右侧。
因此,按钮标签的宽度是200 pt,与按钮宽度相同。我需要我的标题标签与右侧和左侧的空格一致,因此它意味着标签宽度必须为180pt,然后我将在右侧和左侧有10pt。
我该如何做到这一点?
答
使用titleEdgeInsets
:
button.titleEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right);
在这种情况下
或具体为:
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);