Since IOS 8.1, supporting different height for different row prototype is quite easy.
First in storyboard, setting height constraint for different row prototype, then adding those rows into a single UITableView will show the height constraints are ignored at runtime and the row height is always using the row height configured in TableView row height property.
In order to apply the row height constraint defined in row prototype, add the below code in the viewController's viewDidLoad method
First in storyboard, setting height constraint for different row prototype, then adding those rows into a single UITableView will show the height constraints are ignored at runtime and the row height is always using the row height configured in TableView row height property.
In order to apply the row height constraint defined in row prototype, add the below code in the viewController's viewDidLoad method
tableView.estimatedRowHeight = 44
tableView.rowHeight = UITableViewAutomaticDimension
The estimatedRowHeight can be set to the same value as configured in tableview's row height property.
Note, inside the cell, the vertical constraint must set to require the vertical cell height. For example, if a button has top and bottom and height constraints added as the cell height, it will work. But if the button only has top and height constraints, then it will not work, as the cell will be shrunked to estimated row height.
Note, inside the cell, the vertical constraint must set to require the vertical cell height. For example, if a button has top and bottom and height constraints added as the cell height, it will work. But if the button only has top and height constraints, then it will not work, as the cell will be shrunked to estimated row height.
No comments:
Post a Comment