Reputation: 288
I have been searching in stack overflow from long time,i found some questions related but not perfect. Can someone explain In detail what are the steps to make label grow its height based on text that is in tableview cell.I want to increase the labels height and then the cells height. Thank You.
Upvotes: 0
Views: 70
Reputation: 98
it boils down to this
var myRowHeight: CGFloat = 100 //initialize this to some value close to what it will probably be
override func viewDidLoad() {
//control row height for variable text size
tableView.estimatedRowHeight = tableView.rowHeight
tableView.rowHeight = myRowHeight
}
override func viewWillAppear(animated: Bool) {
//set row height right before view appears so autolayout has time to estimate it
tableView.estimatedRowHeight = tableView.rowHeight
tableView.rowHeight = UITableViewAutomaticDimension
}
This is the solution that works for me.
Upvotes: 0
Reputation: 353
For iOS 8+ you can find explanation and example here For iOS prior 8 version it's more complicated to do this. You should manually calculate the height of the cell and then provide this heigh in delegate methods of a table view (heighForRow at index path). Hope this will help you.
Upvotes: 1