我找到了如何设置与按钮宽度相对应的最小字体大小的解决方案:
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);
关于ios - 设置带边距的 UIButton 最小字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21006067/