[英]autolayout UILabel's dynamic height calculation doesn't work when text is empty string?
在iOS 8中,我在UITableViewCell
有一个UILabel
。 根据UILabel
的文字,我希望单元格具有动态高度。 它工作正常。 但是当文本是一个空字符串时,它似乎有一个默认高度,但我希望它为零。
这就是我所做的:
masonry
设置单元格的约束。 设置top
, bottom
约束。 tableView.estimatedHeight
heightForRow
委托方法返回UITableViewAutomaticDimension
所以我做错了什么? 有帮助吗?
将heightForRowAtIndexPath的代码更改为此。 这有效!
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *text = [yourDataSourceArray objectAtIndex:indexPath.row];
if(text.length > 0 ){
return UITableViewAutomaticDimension;
}
return 0;
}
[yourLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisVertical];
[yourLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisVertical];
将标签V compress设置为高优先级
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.