swift cell自适应高度

2021-05-19  本文已影响0人  舰_966e

overridefunc viewDidLoad() {

super.viewDidLoad() self.tableView.estimatedRowHeight =100

    self.tableView.rowHeight = UITableViewAutomaticDimension

}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

...... 

            cell.textLabel?.numberOfLines =0 

            cell.textLabel?.preferredMaxLayoutWidth= CGRectGetWidth(tableView.bounds) 

}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

    return UITableViewAutomaticDimension

}

上一篇下一篇

猜你喜欢

热点阅读