Dynamic tableViewCell height

假如想象 提交于 2019-11-27 16:29:50

Setting Dynamic Cell height procedure

  1. Pin the label from top and bottom. Please refer following Screen shot

  1. Set numbers of line to 0 of the label as from property inspector of xcode, it can be done from code too please refer following screen shot

  1. Implement delegates of table view mentioned below

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
    }
    
    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return 50 // also UITableViewAutomaticDimension can be used
    }
    

You are missing the bottom constraint from the label to the table view cell (as far as I can tell). In order to make autolayout know how large the height of the cell has to be, you need to supply those constraints.

In addition do not forget to provide the estimatedRowHeight to the table view. If that value is not given, automatic cell sizing will not work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!