gpt4 book ai didi

objective-c - 如何在 ios 中做多行 UILabel?

转载 作者:IT王子 更新时间:2023-10-29 07:43:55 24 4
gpt4 key购买 nike

我正在动态填充标题 (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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com