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里写下这两句
先设置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的高
相关文章推荐
- iOS应用间调用
- 如何设计一个 iOS 控件?(iOS 控件完全解析)
- 画虚线
- IOS SDK详解之NSDictionary
- iOS开发入门到精通四阶段
- 关于苹果开发者账号的大部分事
- 【iOS9】真机测试添加证书
- ios has ambiguous scrollable content height
- iOS开发-进阶:延时执行的几种方式的比较和汇总
- iOS多线程GCD
- iOS 开发,工程中混合使用 ARC 和非ARC
- iOS开发:获取系统邮箱地址
- AutoLayout中的Content Hugging 和 Content Compression Resistance
- iOS 打包ipa
- iOS学习之点击TableViewcell实现跳转
- iOS从相机或相册获取图片并裁剪,再获取裁剪后的图片
- iOS富文本(二)初识Text Kit
- iOS富文本(二)初识Text Kit
- iOS 开发,工程中混合使用 ARC 和非ARC
- Masonry自动布局详解九:scrollview实战场景