Is it just me or they added a lot more padding to section headers and footers of grouped UITableView
s in iOS 11?
I compiled my app to run with iOS 11 and noticed the extra padding.
I kinda solved it by setting contentInset.top
to a negative value checking if the os is iOS 11, but this is a ugly workaround.
Is there any other better way do clear the extra padding of grouped table views in order to achieve the same results across all supported iOS? It kinda stinks to have multiple checks for such a silly thing.
Screenshot for comparison:
As you can see, on iOS 11 there's extra spacing between sections (yeah, those are sections!).
Short answer is that this extra padding is probably due to the table view header (not the section header), and that UITableView doesn't like to be assigned a header with a height of 0.0.
A view that presents data using rows in a single column. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+
You can remove this by setting a property on the table view: self. tableView.
This is new contentInsetAdjustmentBehavior parameter of UIScrollView which you can set it as .never to prevent extra padding
if #available(iOS 11.0, *) {
tableView.contentInsetAdjustmentBehavior = .never
}
or in storyboard under Size Inspector
In iOS 11 the section footer has a view that adds to the spacing between the sections. You would need to set the view of the footer to nil explicitly in addition to adjusting the height for the footer:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.1;
}
This will make your table view to look like what you had in iOS 10 and would also not have any effect on previous versions of iOS. You can do the same for the header if you don't need the headers.
You just need to set the table view's header and footer view.
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [[UIView alloc] init];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [[UIView alloc] init];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With