Search Your Question

Dynamically set UITableview cell height

Ans : 

For auto cell height in tableview in Swift 3.0

Write following 2 lines of code in viewDidLoad and before reload tableview :

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 44

Following steps must to do otherwise label height will not be increase and so UITableiViewCell.

Label height must be auto incremented using numberOfLines = 0

LineBreak should be set according your need word-wrap, char-wrap, etc...

3 comments:

  1. Thanks. Using above way works for me.
    I want to do more. As label height increase, my cell height should be increase as tableview height also should be increase. How can I achieve this?

    ReplyDelete
  2. You have to put bottom constraint for the UILabel.
    Basically all the elements in the cell should have a constraint for top and bottom in order to push the bottom of the cell to expand.

    Concurrently you can take help of stack views inside a tableView to help if the view becomes that complex

    ReplyDelete

Thanks