iOS:UITableViewCell的动态高度 [英] iOS: Dynamic Height For UITableViewCell

查看:272
本文介绍了iOS:UITableViewCell的动态高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS9 XCode7 我需要根据labelText Height动态更改单元格的高度

I'm using iOS9 XCode7 I need to change the height of cell Dynamically according to labelText Height

我曾经使用过:

self.tableView.rowHeight=UITableViewAutomaticDimension;

但是它不适用于定制单元. sizetoFit已在iOS9中删除.

But it is not working for custom made cell. sizetoFit is removed in iOS9.

请提出一些建议. 谢谢

Please suggest something. Thanks

推荐答案

赋予标签相对于单元格(顶部,底部,左侧和右侧)的约束.

Give your label constrains relative to the cell, top, bottom, left and right.

您的单元格大小将随内容高度而增长.

Than your cell size will grow with the content height.

还可以使标签变为多行.(通过在属性检查器中将Lines属性设置为0)

also make your label multiline.(by setting Lines property to 0 in attribute inspector)

#pragma mark- Menu table Delegates 

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return UITableViewAutomaticDimension;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return UITableViewAutomaticDimension;
}

这篇关于iOS:UITableViewCell的动态高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆