xib自定义cell之自适应高度
2016-08-17 09:27
281 查看
第一种:计算高度
label多行显示,计算size:
CGSize contentSize = [FXAFactory
fc_getStringSizeWith:str boundingRectWithSize:CGSizeMake(kSCREEN_WIDTH -
30, MAXFLOAT)
font:[UIFont
systemFontOfSize:14]];
第二种:用系统自带的方法
1、在自定义cell的.m文件中一定要加上label的宽度
如:self.detail.preferredMaxLayoutWidth = [UIScreen
mainScreen].bounds.size.width -
20;
2、在tableView的dataSouce中
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
self.table.rowHeight =
UITableViewAutomaticDimension;//设置cell的高度为自动计算,只有才xib或者storyboard上自定义的cell才会生效,需要在xib中设置好约束
self.table.estimatedRowHeight =
240;//必须设置好预估值
return self.table.rowHeight;
}
第三种:获取复用的Cell后模拟赋值,然后取得Cell高度
1、在自定义cell的.m文件中一定要加上label的宽度
如:self.detail.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - 20;
2、
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
MainCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"MainCell"];
cell.imgView.image = [UIImage
imageNamed:[self.dataSoruce[indexPath.row]
objectForKey:@"image"]];
cell.text.text = [self.dataSoruce[indexPath.row]
objectForKey:@"name"];
cell.detail.text = [self.dataSoruce[indexPath.row]
objectForKey:@"detail"];
[cell.contentView
layoutIfNeeded];
[cell.contentView
updateConstraintsIfNeeded];//更新约束
CGSize size = [cell.contentView
systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height +
1;
}
label多行显示,计算size:
CGSize contentSize = [FXAFactory
fc_getStringSizeWith:str boundingRectWithSize:CGSizeMake(kSCREEN_WIDTH -
30, MAXFLOAT)
font:[UIFont
systemFontOfSize:14]];
第二种:用系统自带的方法
1、在自定义cell的.m文件中一定要加上label的宽度
如:self.detail.preferredMaxLayoutWidth = [UIScreen
mainScreen].bounds.size.width -
20;
2、在tableView的dataSouce中
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
self.table.rowHeight =
UITableViewAutomaticDimension;//设置cell的高度为自动计算,只有才xib或者storyboard上自定义的cell才会生效,需要在xib中设置好约束
self.table.estimatedRowHeight =
240;//必须设置好预估值
return self.table.rowHeight;
}
第三种:获取复用的Cell后模拟赋值,然后取得Cell高度
1、在自定义cell的.m文件中一定要加上label的宽度
如:self.detail.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - 20;
2、
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
MainCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"MainCell"];
cell.imgView.image = [UIImage
imageNamed:[self.dataSoruce[indexPath.row]
objectForKey:@"image"]];
cell.text.text = [self.dataSoruce[indexPath.row]
objectForKey:@"name"];
cell.detail.text = [self.dataSoruce[indexPath.row]
objectForKey:@"detail"];
[cell.contentView
layoutIfNeeded];
[cell.contentView
updateConstraintsIfNeeded];//更新约束
CGSize size = [cell.contentView
systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height +
1;
}
相关文章推荐
- 关于用xib自定义的cell的高度自适应问题
- UILabel,自定义cell的自适应高度
- iOS学习笔记 自定义cell并且文本自适应高度
- UIday1101:UITableView 3 自定义cell 多种cell混合使用 cell自适应高度
- 爬爬爬之路:UI(十一) UITableView(三) 自定义Cell 多Cell混合 自适应高度 及cell的状态控制
- 比较两个Image对象是否相等、xib中设置自定义整个cell的高度
- iOS个人整理20-UITableViewCell自定义,cell高度的自适应(纯代码)
- UI_11 自定义UITableViewCell、Cell的高度自适应
- UI课程11 自定义cell及自适应高度
- Cell自适应高度及自定义cell混合使…
- Cell自适应高度及自定义cell混合使…
- 自定义 cell 自适应高度
- UI一揽子计划 11 (自定义UITableViewCell、Cell 的自适应高度)
- 自动布局小知识--UITableViewCell自定义高度,Label长度自适应
- 自定义cell自适应高度
- Cell自适应高度及自定义cell混合使用
- iOS雨笙 lable自适应高度(多用于tableview的自定义cell中)
- 用XIB创建自适应高度的TableviewCell
- 进击的KFC:利用Xib来创建UItableviewCell,并实现cell的自适应高度
- textView放在自定义cell里面-自适应高度