Dynamic Height Issue for UITableView Cells (Swift)

前端 未结 25 2582
温柔的废话
温柔的废话 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:49

    Dynamic sizing cell of UITableView required 2 things

    1. Setting the the right constraint of your view inside the table view cell (mostly it includes giving your view proper top , bottom and traling constraints)
    2. Calling these properties of TableView in viewDidLoad()

       tableView.rowHeight = UITableViewAutomaticDimension
      
       tableView.estimatedRowHeight = 140
      

    This is a wonderfull tutorial on self-sizing (dynamic table view cells) written in swift 3 .

提交回复
热议问题