【问题标题】:Dynamic cell height for tableview [closed]表格视图的动态单元格高度[关闭]
【发布时间】:2015-04-16 14:09:52
【问题描述】:

我正在开发 UITableView,并且单元格具有不同的内容,例如 Facebook 单元格,那么我如何相应地更改每个单元格的高度?

【问题讨论】:

标签: ios objective-c uitableview


【解决方案1】:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

UIFont *font = [UIFont systemFontOfSize:20];
NSDictionary *userAttributes = @{NSFontAttributeName: font,
                             NSForegroundColorAttributeName:         [UIColor blackColor]};
NSString *text = @"Your label text";

CGSize textSize = [text sizeWithAttributes: userAttributes];

ht = 20;

if (textSize.width > [FunctionUtils getViewWidth]) {

ht = (textSize.width/([FunctionUtils getViewWidth]));
ht = (ceil(ht))*20+35;
//20 font size
}

return ht;
}

【讨论】:

    【解决方案2】:

    您应该点击链接http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout 这是实现此目的的最佳方式

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-15
      • 1970-01-01
      • 2018-05-06
      • 1970-01-01
      相关资源
      最近更新 更多