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

标签 objective-c ios uilabel multiline

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

相关文章:

iphone - 刷新 MasterView XML 解析文件 - Objective C

ios - AVCaptureVideoPreviewLayer捕获角度缩短了吗?

iOS强制App使用自定义键盘

ios - 为什么 sizeThatFits 不能与 UILabel 一起使用?

iphone - iOS - 如何实现UILabel上文字的浮雕效果?

ios - 使用作为参数传递的 UIColor 设置 CGContextSetStrokeColorWithColor

iphone - 从相机胶卷中选择的视频的 URL

ios - 核心数据实体重命名

iphone - 解析xml内容标签

objective-c - 如何根据我们拥有的文本设置 UILabel 的高度