ios - Word Wrap 不适用于 UILabel

标签 ios objective-c uilabel

使用自动版式我无法在代码中覆盖我的标签。我在 IB 中设置了标签属性:Lines = 0,LineBreaks = Word Wrap,但我将高度设置为单行,因为选择的单元格决定了标签中的文本。所以有时标签只会有一行。

在我看来DidLoad:

myLabel.text = @”blah, blah, blah….”;
[myLabel setLineBreakMode:NSLineBreakByWordWrapping];
myLabel.numberOfLines  = 0; //have tried 1 but didn’t help
[myLabel sizeToFit];

这适用于另一个项目,但我没有使用 AutoLayout。 AutoLayout 似乎覆盖了这些设置。
我什至添加了

[myLabel setFrame:CGRectMake(20, 135, 280, 80); 

但这并没有帮助。

最佳答案

允许标签的固有尺寸决定高度。您需要将 numberOfLines 属性设置为 0 是正确的。由于您使用的是 AutoLayout,因此不要调用 sizeToFit 并且您需要设置标签的 preferredMaxLayoutWidth。

关于ios - Word Wrap 不适用于 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25142777/

相关文章:

ios - 具有恒定大小和动态字体大小的 UILabel 取决于文本

ios - 使用 UIActivityViewController 共享 URL 时,如何让 "Open in Safari"图标出现?

objective-c - 无法在 iOS7 中自定义 UIProgressView?

iphone - iPhone 应用程序中的多线程问题?

ios - 如何在 iPhone UILabel 中设置字距调整

ios - 无法分配给属性 : 'width' is a get-only property

iOS 8 (Swift) 如何摆脱这个错误 : ImageIO: PNG zlib error?

ios - RCTLinking > 问题 > 指针缺少可空性类型说明符(_Nonnull、_Nullable 或 _Null_unspecified)

ios - 保留 AppStore 名称 - Placeholder iPhone App Time Limits

iphone - MKMap 不使用定义的纬度和经度