Autolayout UITableViewCell的子视图效果不佳

时间:2014-04-24 09:07:28

标签: ios objective-c uitableview uiview

UITabelViewCell中,添加UIViewUILabel时出现问题。
我认为UILabel具有动态高度,UIView具有固定的Rect。 首先,translatesAutoresizingMaskIntoConstraints = NO对他们两个, 并标记为preferredMaxLayoutWidth = 280numberOfLines = 0

约束,如下:

NSDictionary *views = @{@"_label":self.label,@"_view":self.view};

[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[_label]-|"
                                                                  options:0
                                                                  metrics:nil
                                                                    views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[_view]-|"
                                                                  options:0
                                                                  metrics:nil
                                                                    views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[_label(100@300)]-[_view(20)]-|"
                                                                  options:0
                                                                  metrics:nil
                                                                    views:views]];

完成后,标签只有一行,并且有一些例外:

 (
 "<NSLayoutConstraint:0x8cdb450 V:|-(NSSpace(20))-[UILabel:0x8cda6e0]   (Names: '|':UITableViewCellContentView:0x8cd9e40 )>",
"<NSLayoutConstraint:0x8cdb530 V:[UIView:0x8cda930(20)]>",
"<NSLayoutConstraint:0x8cdb560 V:[UIView:0x8cda930]-(NSSpace(20))-|   (Names: '|':UITableViewCellContentView:0x8cd9e40 )>",
"<NSAutoresizingMaskLayoutConstraint:0x8cdb100 h=--& v=--& V:[UITableViewCellContentView:0x8cd9e40(44)]>",
"<NSLayoutConstraint:0x8a88de0 V:[UILabel:0x8cda6e0]-(NSSpace(8))-[UIView:0x8cda930]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x8a88de0 V:[UILabel:0x8cda6e0]-(NSSpace(8))-[UIView:0x8cda930]>

0 个答案:

没有答案