ios学习笔记: TableView利用label调整cell高度
来源:互联网 发布:网络综艺节目的发展 编辑:程序博客网 时间:2024/05/17 23:16
tableView中:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//模拟数据
MC_EatCommentModel* model = [self.commentItemsobjectAtIndex:indexPath.row];
//根据labei设置高度
CGSize size =CGSizeMake(260,1000);
CGSize labelSize = [model.commentsizeWithFont:[UIFontsystemFontOfSize:12.0]constrainedToSize:sizelineBreakMode:NSLineBreakByWordWrapping];
return labelSize.height +44;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
staticNSString *CellIdentifier =@"MC_EatCommentCell";
BOOL nibsRegistered =NO;
if (!nibsRegistered) {
UINib *nib = [UINibnibWithNibName:NSStringFromClass([MC_EatCommentCellclass])bundle:nil];
[tableView registerNib:nibforCellReuseIdentifier:CellIdentifier];
nibsRegistered = YES;
}
MC_EatCommentCell *cell = (MC_EatCommentCell *)[tableViewdequeueReusableCellWithIdentifier:CellIdentifier];
self.commentModel = [self.commentItemsobjectAtIndex:indexPath.row];
cell.userName.text=self.commentModel.userName;
cell.label_time.text=self.commentModel.time;
//自适应高度,传入cell中
[cell setCommentText:self.commentModel.comment];
cell.m_userModel =self.commentModel;
[cell.iconsetBackgroundImage:[UIImageimageNamed:self.commentModel.icon]forState:UIControlStateNormal];
return cell;
}
cell中:-(void)setCommentText:(NSString*)text{
self.comment.text = text;
//设置label的最大行数,这里设为0,而用 size.height去限制高度。eg当设置为3时 label会自动调节高度,不再紧贴着label上方
self.comment.numberOfLines =0;
CGSize size =CGSizeMake(260,1000);
CGSize labelSize = [self.comment.textsizeWithFont:self.comment.fontconstrainedToSize:sizelineBreakMode:NSLineBreakByWordWrapping];
self.comment.frame =CGRectMake(self.comment.frame.origin.x,self.comment.frame.origin.y, labelSize.width, labelSize.height);
self.comment.textAlignment =NSTextAlignmentLeft;
}
参考:http://blog.csdn.net/swingpyzf/article/details/18093959- ios学习笔记: TableView利用label调整cell高度
- 【iOS知识学习】_iOS动态改变TableView Cell高度
- 【iOS知识学习】_iOS动态改变TableView Cell高度
- 【iOS知识学习】_iOS动态改变TableView Cell高度
- IOS tableView cell动态高度 (autoLayout)
- ios tableview 自动计算cell高度
- [iOS]TableView的Cell高度自适应
- label 调整label高度
- iOS cell 的自适应高度 中 返回label的高度
- ios开发笔记之如何让tableView根据文本内容动态改变cell的高度
- iOS学习之路01(根据label的内容更改cell的高度)
- iOS 8 Tableview根据AutoLayout自动调整高度,iostableview高度
- 【学习笔记】tableview 文字设置 缩进,头尾标题 间距,cell高度 点击 分割线
- iOS学习笔记 自定义cell并且文本自适应高度
- iOS 中 cell和 label 的自适应高度
- iOS中cell自适应文本Label高度篇
- IOS TableView的Cell高度自适应,UILabel自动换行适应
- IOS TableView的Cell高度自适应,UILabel自动换行适应
- Sqoop-1.4.4工具import和export使用详解
- 关于Fragment API版本兼容问题
- xUtils 关联对象查询
- C#中的匿名方法实例解析
- offsetof(s,m)解析
- ios学习笔记: TableView利用label调整cell高度
- 千山万水之Hibernate(十)——抓取策略
- 随机数
- open failed: EBUSY (Device or resource busy)
- Service类onStartCommand()返回值讲解.
- [LeetCode] Contains Duplicate(II,III)
- 某大学程序设计竞赛
- 2014.4新版uboot启动流程分析
- leetcode--Contains Duplicate