iOS实现Cell自适应高度
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 ;/