xib中label多行显示的高度问题

用xib自定义cell时,给label的添加约束:(top:10,  leading:10,  trailing:10,  height:10)

注:label设置numberOfLines = 0, 多行显示的.

问题:

当用代码修改height的约束时,报下面的错.

不用代码修改height的约束时, 错误消失.???

解决方法:

删除height的约束,label会自适应,label的高度可以计算出来,用boundingRectWithSize

然后计算出cell的高度.

错误信息:

Unable to simultaneously satisfy constraints.Probably at least one of the constraints in the following list is one you don't want.

 Try this: (1) look at each constraint and try to figure out which you don't expect;

 (2) find the code that added the unwanted constraint or constraints and fix it.

(

"<NSLayoutConstraint:0x7d1b1630 UIImageView:0x7d1b1520.height == 40>"

"<NSLayoutConstraint:0x7d1bb780 UILabel:0x7d1b0920.height == 225.031>"

"<NSLayoutConstraint:0x7d1b0cc0 UIImageView:0x7d1b0bb0.height == 20>"

"<NSLayoutConstraint:0x7d1b1bc0 UIButton:0x7d1b1a60.height == 30>"

"<NSLayoutConstraint:0x7d1b1000 UIImageView:0x7d1b0f20.height == 1>"

"<NSLayoutConstraint:0x7d1bccb0 UIImageView:0x7d1b1520.top == UITableViewCellContentView:0x7d1b1420.top + 5>"

"<NSLayoutConstraint:0x7d1bcd40 UILabel:0x7d1b0920.top == UIImageView:0x7d1b1520.bottom + 10>"

"<NSLayoutConstraint:0x7d1bd350 UIView:0x7d1bc7d0.top == UILabel:0x7d1b0920.bottom + 10>"

"<NSLayoutConstraint:0x7d1bd470 UIImageView:0x7d1b0f20.top == UIView:0x7d1bc7d0.bottom + 10>"

"<NSLayoutConstraint:0x7d1be6c0 UIButton:0x7d1b1a60.top == UIImageView:0x7d1b0f20.bottom>"

"<NSLayoutConstraint:0x7d1be6f0 UITableViewCellContentView:0x7d1b1420.bottom == UIImageView:0x7d1b0bb0.bottom>"

"<NSLayoutConstraint:0x7d1be720 UIImageView:0x7d1b0bb0.top == UIButton:0x7d1b1a60.bottom>"

"<NSLayoutConstraint:0x7d75eb20 UITableViewCellContentView:0x7d1b1420.height == 217.375>"

)

Will attempt to recover by breaking constraint

"<NSLayoutConstraint:0x7d1bb780 UILabel:0x7d1b0920.height == 225.031>"

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.

The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 写在前面 iOS的的布局机制「auto layout」不是一个新概念,它早在iOS 6中就推出来了,当下距离iOS...
    西门淋雨阅读 1,593评论 2 4
  • Note from Ray:Tutorial Team member Matthijs Hollemans (th...
    Samboo阅读 574评论 2 1
  • 一、前言 关于苹果的布局一直是我比较纠结的问题,是写代码来控制布局,还是使用storyboard来控制布局呢?以前...
    iplaycodex阅读 2,494评论 0 1
  • 一缕清风走过 掀起我那青丝 随风飘荡着 桂枝何时蒙上一层花蕾 池塘里的睡莲何时睁开眼 不知,银杏已换了季 ...
    宸淏阅读 179评论 0 0
  • 初恋是第一个喜欢的人吧,那时候的喜欢很纯粹对方的一个笑容一句温柔话语足以让你兴奋一整天甚至夜晚时候还在床上翻来覆去...
    许知颜阅读 479评论 2 2