Dynamic tableViewCell height

前端 未结 2 921
孤街浪徒
孤街浪徒 2020-12-04 04:22

I have a tableViewCell with a label inside that could be multiple lines tall. I\'ve set the label\'s Lines property to 0. However, when I make the label\'s text

2条回答
  •  醉酒成梦
    2020-12-04 05:05

    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
      }
      

提交回复
热议问题