Skip to content

Instantly share code, notes, and snippets.

@kishikawakatsumi
Created April 29, 2020 11:19
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kishikawakatsumi/612cbcf756ce6c0a1a0afd8fb5bb2825 to your computer and use it in GitHub Desktop.
Save kishikawakatsumi/612cbcf756ce6c0a1a0afd8fb5bb2825 to your computer and use it in GitHub Desktop.
Auto sizing UITableView header
...
headerView.translatesAutoresizingMaskIntoConstraints = false
tableView.tableHeaderView = headerView
NSLayoutConstraint.activate([
headerView.topAnchor.constraint(equalTo: tableView.topAnchor),
headerView.widthAnchor.constraint(equalTo: tableView.widthAnchor),
headerView.centerXAnchor.constraint(equalTo: tableView.centerXAnchor)])
tableView.tableHeaderView?.layoutIfNeeded()
tableView.tableHeaderView = headerView
@omochi
Copy link

omochi commented Apr 29, 2020

@vladborovtsov
Copy link

Still works in 2023! thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment