Member-only story
Is it possible to obtain a dynamic table view section header height using Auto Layout?
1 min readNov 14, 2019
If you need both section as well row with dynamic height based on content then you can use below code:
On viewDidLoad() write this lines:
self.globalTableView.estimatedRowHeight = 20
self.globalTableView.rowHeight = UITableView.automaticDimension self.globalTableView.sectionHeaderHeight = UITableView.automaticDimension
self.globalTableView.estimatedSectionHeaderHeight = 25;
Now we have set row height and section height by using UITableView Delegate methods:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return UITableView.automaticDimension }
For more about iOS development : https://medium.com/@javedmultani16
Some useful codes and libraries: https://github.com/javedmultani16
Know more about me: https://www.linkedin.com/in/javedmultani16/