How to create dynamic tableview cell with dynamic tableview height in iOS

前端 未结 4 789
太阳男子
太阳男子 2021-01-26 23:14

I want to increase tableview cell and tableview height based on content. Suppose tableview contain 2 record and his 1st cell height is 100 and 2nd cell height is 25 then tablevi

4条回答
  •  梦毁少年i
    2021-01-26 23:28

    If you are running iOS 8+, You can use:

    tableView.rowHeight = UITableViewAutomaticDimension
    tableView.estimatedRowHeight = 80 // your desired or expected height
    

    properties.

    1. for this to take effect you should not have any height set in heightForRowAtIndexpath
    2. You should set the cell constraints i.e., constraints for the elements present inside cell, so the set constraints are enough for the tableviewcell to calculate it's height in run time

提交回复
热议问题