如何在ios中进行多行UILabel? [英] How to do multiline UILabel in ios?

查看:84
本文介绍了如何在ios中进行多行UILabel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在动态填充标题(UILabel)。有时它太长了,IOS挤压字体以适应宽度。有没有办法使用相同的字体大小做多行?

I'm dynamically populating the title (UILabel). Sometime it's bit too long and IOS squeeze the font to fit in the width. Is there a way to do multiline with using same font size?

推荐答案

设置adjustsFontSizeToFitWidth 到NO和 numberOfLines 为0。

Set adjustsFontSizeToFitWidth to NO and numberOfLines to 0.


此属性控制要使用的最大行数,以使
将标签的文本放入其边界矩形。此属性的默认值
为1. 要删除任何最大限​​制,并根据需要使用尽可能多的
行,请将此属性的值设置为0.

如果使用此属性约束文本,则任何不是
的文本都在最大行数内并且在标签的边界
矩形内是使用适当的换行符
模式截断。

If you constrain your text using this property, any text that does not fit within the maximum number of lines and inside the bounding rectangle of the label is truncated using the appropriate line break mode.

当使用sizeToFit方法调整接收器大小时,调整
的大小会考虑存储在此中的值属性。例如,如果
此属性设置为3,则sizeToFit方法会调整接收器
的大小,使其大到足以显示三行文本。

When the receiver is resized using the sizeToFit method, resizing takes into account the value stored in this property. For example, if this property is set to 3, the sizeToFit method resizes the receiver so that it is big enough to display three lines of text.

您可能还想指定 lineBreakMode 除非默认 UILineBreakModeWordWrap 是适合你想要的。

You may additionally want to specify the lineBreakMode unless the default UILineBreakModeWordWrap is suitable for what you want.

这篇关于如何在ios中进行多行UILabel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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