Since I discovered AutoLayout I use it everywhere, now I\'m trying to use it with a tableHeaderView.
I made a subclass of
Any constraint-based UIView can be a good tableHeaderView.
One needs to set a tableFooterView before and then impose additional trailing constraint on tableFooterView and tableHeaderView.
- (void)viewDidLoad {
........................
// let self.headerView is some constraint-based UIView
self.tableView.tableFooterView = [UIView new];
[self.headerView layoutIfNeeded];
self.tableView.tableHeaderView = self.headerView;
[self.tableView.leadingAnchor constraintEqualToAnchor:self.headerView.leadingAnchor].active = YES;
[self.tableView.trailingAnchor constraintEqualToAnchor:self.headerView.trailingAnchor].active = YES;
[self.tableView.topAnchor constraintEqualToAnchor:self.headerView.topAnchor].active = YES;
[self.tableFooterView.trailingAnchor constraintEqualToAnchor:self.headerView.trailingAnchor].active = YES;
}
One can find all details and code snippets here