您的位置:首页 > 移动开发 > IOS开发

iOS实现Cell自适应高度

2015-11-30 17:36 381 查看
1.实现UITableViewDelegate中的方法

先设置cell的contentview中label根据内容自动换行

numberOfLines=0

实现UITableViewDelegate中的方法

- (CGFloat)tableView:(UITableView )tableView estimatedHeightForRowAtIndexPath:(NSIndexPath )indexPath{

return UITableViewAutomaticDimension;

}

2.根据content view设置cell的frame

先设置cell的contentview中label根据内容自动换行

numberOfLines=0

cell根据Label大小 修改cell此时的尺寸

CGRect bounds = cell.contentLb.bounds;

bounds.size.height = bounds.size.height + 10;

cell.bounds = bounds;

或者在viewDidLoad里写下这两句

self.chatTableView.rowHeight = UITableViewAutomaticDimension;
self.chatTableView.estimatedRowHeight = 70;//这句必须写上值可以为自己估算的cell的高
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: