我正在动态填充标题 (UILabel)。有时它有点太长,IOS 会压缩字体以适应宽度。有没有一种方法可以使用相同的字体大小来实现多行?
最佳答案
设置adjustsFontSizeToFitWidth
NO 和 numberOfLines
到 0。
numberOfLines Docs
This property controls the maximum number of lines to use in order to fit the label’s text into its bounding rectangle. The default value for this property is 1. To remove any maximum limit, and use as many lines as needed, set the value of this property to 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.
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
适合你想要的。
关于objective-c - 如何在 ios 中做多行 UILabel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7996108/