1
我想用自动布局自动调整表格单元格的大小。但似乎TableView忽略高度限制。如何使用砌体自动布局UItableviewCell高度
UIImage的和的UILabel中的UITableViewCell:
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.icon = [[UIImageView alloc] init];
[self.contentView addSubview:self.icon];
[self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView).with.offset(10);
make.left.equalTo(self.contentView).with.offset(10);
make.width.offset(70);
make.height.offset(70);
// make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-10);
}];
self.icon.backgroundColor = [UIColor redColor];
self.customText = [[UILabel alloc] init];
self.customText.text = @"xx11dragon";
self.customText.backgroundColor = [UIColor yellowColor];
self.customText.numberOfLines = 0;
self.customText.lineBreakMode = NSLineBreakByCharWrapping;
[self.contentView addSubview:self.customText];
[self.customText mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView).with.offset(10);
make.left.equalTo(self.icon.mas_right).with.offset(10);
make.right.equalTo(self.contentView.mas_right).with.offset(-10);
// make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-10);
}];
在UITableViewClass:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
_cell.title.text = [dict objectForKey:@"title"];
_cell.customText.text = [dict objectForKey:@"content"];
[_cell setNeedsLayout];
[_cell layoutIfNeeded];
CGSize size = [_cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
NSLog(@"%f",size.height);
return size.height + 1;
}
size.height等于0.0F
的UITableViewCell高度等于或UIImage的底部的UILabel + 10px的,如何设置底部?