您的位置:首页 > 移动开发 > Swift

swift UITableView cell自适应高度

2015-07-26 22:50 316 查看
ios8支持:

1.

override func viewDidLoad() {
super.viewDidLoad()

self.tableView.estimatedRowHeight = 100
self.tableView.rowHeight = UITableViewAutomaticDimension
}


2.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
......
cell.textLabel?.numberOfLines = 0
cell.textLabel?.preferredMaxLayoutWidth = CGRectGetWidth(tableView.bounds)
}


3.
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: