根据UILabel文本的数量增加tableview单元格的高度 [英] Increase height of tableview cell according to amount of UILabel text
本文介绍了根据UILabel文本的数量增加tableview单元格的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过使用自动布局根据文本量更改表格单元格的高度.我已经尝试了以下代码,但没有用:
I want to change the height of my tableview cell according to the amount of text by using auto layout. I have tried the following code but it doesn't work:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
AddTaskDetails *addTaskDetail = (self.tasksArray)[indexPath.row];
CGFloat height;
float textcount = [addTaskDetail.taskDetail length];
if(textcount>60)
{
height = textcount-20;
NSLog(@"%d,%f",indexPath.row,height);
}
else
{
height = 70;
}
return height;
}
推荐答案
您将需要在要呈现的字符串上使用 boundingRectWithSize:options:attributes:context .
You will need to use boundingRectWithSize:options:attributes:context on the string to be rendered.
这是一个常见问题,当您搜索具有动态高度的UITableViewCell"时,您可能会找到代码段.
This is a frequently asked question and you may find code snippets when you search for 'UITableViewCell with dynamic height'.
这篇关于根据UILabel文本的数量增加tableview单元格的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文