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

查看:21
本文介绍了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,并且我的字符串也有换行符 ( ),我选择了 linebreakmodewordwrap.也许有人和我现在的情况一样,可以帮助我吗?我真的很感激.

In my xib, UILabels autoshrink is checked, also number of lines is set to 0, and also my string has new line symbols ( ), 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).

设置此属性时,minimumScaleFactor 也必须设置(默认值为 0.5).

When setting this property, minimumScaleFactor MUST be set too (a good default is 0.5).

var adjustsFontSizeToFitWidth: Bool { get set }

目标-C

@property(nonatomic) BOOL adjustsFontSizeToFitWidth;


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


A Boolean value indicating whether spacing between letters should be adjusted to fit the string within the label’s bounds rectangle.

var allowsDefaultTighteningForTruncation: Bool { get set }

目标-C

@property(nonatomic) BOOL allowsDefaultTighteningForTruncation;

来源.

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

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