Dynamic Height Issue for UITableView Cells (Swift)

前端 未结 25 2583
温柔的废话
温柔的废话 2020-11-28 04:39

Dynamic text of variable length are being injected into tableview cell labels. In order for the tableview cells\' heights to be dynamically sized, I have implemented in

25条回答
  •  情歌与酒
    2020-11-28 04:59

    To make autoresizing of UITableViewCell to work make sure you are doing these changes :

    • In Storyboard your UITableView should only contain Dynamic Prototype Cells (It shouldn't use static cells) otherwise autoresizing won't work.
    • In Storyboard your UITableViewCell's UILabel has configured for all 4 constraints that is top, bottom, leading and trailing constraints.
    • In Storyboard your UITableViewCell's UILabel's number of lines should be 0
    • In your UIViewController's viewDidLoad function set below UITableView Properties :

      self.tableView.estimatedRowHeight =  
      self.tableView.rowHeight = UITableViewAutomaticDimension
      

提交回复
热议问题