ios - 具有自动布局的多行 UILabel 不起作用

标签 ios storyboard uilabel autolayout multiline

我正在尝试设置约束以在静态表格 View 单元格中获取多行标签,但显然这对我不起作用,标签仍然在一行中。我已将 numberOfLines 属性设置为 0,并将高度限制设置为大于或等于。我在 tableView:heightForRowAtIndexPath 中正确设置了单元格的高度。请查看我的屏幕截图以查看 IB 中的设置。

enter image description here

最佳答案

在上面的评论中,您提到您目前没有设置 preferredMaxLayoutWidth。此属性告诉您的标签,它应该在该属性值的宽度上布置其文本。在 UILabel.h 中:

If nonzero, this is used when determining -intrinsicContentSize for multiline labels

换句话说,如果您不设置它,则标签的固有内容大小是标签绘制其文本所需的任何宽度。如果将此属性设置为标签的边界,它将在下一行开始绘制(否则,如果 numberOfLines 为 0,它将切断文本)。

对于您的情况,我可能会在 tableView:willDisplayCell:forRowAtIndexPath: 中执行此操作。

关于ios - 具有自动布局的多行 UILabel 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23064004/

相关文章:

ios - 在 viewController 转换完成后 removeFromSuperview。

ios - 当打开由 Xcode 4.6 制作的 Storyboard时,Xcode 5 崩溃

ios - 如何根据 iOS 版本加载多个 Storyboard文件? (5 和 6)

ios - 动画更改 UILabel 的字体

ios - UIImage 是否具有 myLabel.hidden = YES 的等价物?

ios - UILabel 自动换行+多行

ios - 在 UITableViewController 中为多个实例初始化结构的位置

ios - iPhone:UISearchBar 如何搜索 ""字符串?

ios - 在 iOS 中共享 vcf 文件时,该文件未使用 swift 附加到邮件中

ios - 如何调试 Storyboard中的自定义字体?