I\'m having trouble resizing a tableHeaderView. It simple doesn\'t work.
1) Create a UITableView and UIView (100 x 320 px);
2) Set the UIView as tableHeaderV
This is only for when you use auto-layout and set translatesAutoresizingMaskIntoConstraints = false
to a custom header view.
The best and the simplest way is to override intrinsicContentSize
. Internally UITableView
uses intrinsicContentSize
to decide its header/footer size. Once you have override intrinsicContentSize
in your custom view, What you need to do is as below
invalidateIntrinsicContentSize()
tableView.setNeedsLayout()
and tableView.layoutIfNeeded()
Then the UITableView
's header/footer will be updated as you want. No need to set the view nil or reset.
One thing really interesting for the UITableView.tableHeaderView
or .tableFooterView
is that UIStackView
loose its ability to manage its arrangedSubviews
. If you want to use UIStackView
as a tableHeaderView or tableFooterView, you have to embed the stackView in a UIView
and override UIView
's intrinsicContentSize
.