UILabel不会自动缩小文本以适合标签大小 [英] UILabel is not auto-shrinking text to fit label size

查看:298
本文介绍了UILabel不会自动缩小文本以适合标签大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个奇怪的问题,我现在处理它超过8小时..根据情况,我必须动态计算 UILabels 大小,


例如我的 UIViewController 收到一个事件,我改变 UILabels 大小。从大到小。我的 UILabel 的大小变小了,我得到了正确的大小,但我的 UILabel 中的文字保持不变,相同的字体大小等我需要字体变小,整个文本适合 UILabel 。所以问题是如何使文本适合我的标签 autoshrinking 或类似的东西?

I have this strange issue, and im dealing with it for more than 8 hours now.. Depending on situation i have to calculate UILabels size dynamically,
e.g
my UIViewController receives an event and i change UILabels size. from bigger to smaller. The size of my UILabel gets smaller and i get the correct needed size, but the text in my UILabel stays the same, the same font size and etc. I need the font to get smaller, for the whole text to fit the UILabel. So the question is how to make the text to fit my label with autoshrinking or something like that?

在我的 xib UILabels autoshrink 已选中,同时行数设置为0,我的字符串也有新行符号(\ n),我选择 linebreakmode wordwrap 。也许有人和我现在的情况相同,可以帮助我吗?我真的很感激。

In my xib, UILabels autoshrink is checked, also number of lines is set to 0, and also my string has new line symbols (\n), and i've selected linebreakmode to wordwrap. Maybe anyone was in the same situation as i am now, and could help me? I would really appreciate that.

提前感谢!

编辑: UILabel 最小字体大小设置为10

UILabel minimum font size is set to 10

推荐答案

如果你还是寻找更好的解决方案,我认为这就是你想要的:

In case you are still searching for a better solution, I think this is what you want:

一个布尔值,指示是否应减小字体大小以适应标题字符串进入标签的边界矩形。(仅当numberOfLines属性设置为1时,此属性才有效。)

A Boolean value indicating whether the font size should be reduced in order to fit the title string into the label’s bounding rectangle. (This property is effective only when the numberOfLines property is set to 1.)

@property(nonatomic) BOOL adjustsFontSizeToFitWidth

一个布尔值,指示是否应调整字母间的间距使字符串适合标签的边界矩形。

@property(nonatomic) BOOL adjustsLetterSpacingToFitWidth

来源

这篇关于UILabel不会自动缩小文本以适合标签大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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