Fork me on https://github.com

swift UITableView cell自适应高度

swift UITableView cell自适应高度

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  
}  

 

posted @ 2016-01-06 21:38  OrangesChen  阅读(1139)  评论(0编辑  收藏  举报