Dynamically increase height of UILabel & TableView Cell?

前端 未结 7 1701
广开言路
广开言路 2020-12-01 12:52

I have a UITableView in which i am displaying a custom cell.I my cell i have two label & one view as below in picture.

I have given constraint of left v

相关标签:
7条回答
  • 2020-12-01 13:27

    Swift 4.2

    For the Basic or Subtitle type of cell, first in viewDidLoad you do this:

        self.tableView.estimatedRowHeight = 44 // This is the default cell height
        self.tableView.rowHeight = UITableView.automaticDimension
    

    Then select the Title and set its number of lines to 0. Now the row will adjust its height based on the Title text. You don't need to do anything else.

    Same goes for your Custom cell types. Make sure the Label which you use in your custom cell is set for 0 lines as well.

    0 讨论(0)
提交回复
热议问题