您的位置:首页 > 编程语言

纯代码TableView自适应高度(很老的使用方法)

2015-10-26 09:13 525 查看
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
cell.textLabel.numberOfLines = 100;
cell.textLabel.font = [UIFont systemFontOfSize:15];
cell.textLabel.text = self.arr[indexPath.row];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

NSString* text = self.arr[indexPath.row];

CGSize constraint = CGSizeMake(375-40, 100);

NSAttributedString* attributedText = [[NSAttributedString alloc]initWithString:text attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}];

CGRect rect = [attributedText boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin context:nil];

CGSize size = rect.size;

CGFloat height = MAX(size.height, 20);
NSLog(@"%f",height);
return height+10;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: