设置带边距的最小字体大小 UIButton [英] Set minimum font size UIButton with margin

查看:44
本文介绍了设置带边距的最小字体大小 UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了如何设置与按钮宽度相对应的最小字体大小的解决方案:

I have found solution how to set minimum font size that will correspond to width of my button:

button.titleLabel.numberOfLines = 1;
button.titleLabel.adjustsFontSizeToFitWidth = YES;
button.titleLabel.lineBreakMode = NSLineBreakByClipping;

但是我怎样才能在左侧和右侧添加边距.

But how can I add margin to the left and right side.

所以按钮标签的宽度是 200 pt,与按钮宽度相同.我需要我的标题标签在右侧和左侧有空格,所以这意味着标签宽度必须是 180pt,然后我将在右侧和左侧有 10pt.

So the width of the buttons label is 200 pt the same as the button width. I need my title label to be with the spaces on the right and left side so it means the label width must be 180pt for example and then I will have 10pt on the right and on the left sides.

我怎样才能做到这一点?

How can I achieve this?

推荐答案

Use titleEdgeInsets:

button.titleEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right);

或者特别是在这种情况下:

or specifically in this case:

button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);

这篇关于设置带边距的最小字体大小 UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆