Did they add more padding to UITableVIew in iOS 11?

Viewed 5585

Is it just me or they added a lot more padding to section headers and footers of grouped UITableViews 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:

iOS 10 vs iOS 11 UITableView comparison

As you can see, on iOS 11 there's extra spacing between sections (yeah, those are sections!).

7 Answers

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

enter image description here

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];
}

I had a similar problem I think it was a bug in the Old Xcode.

If you are using autolayout and you have Content View and views inside this, Constrain to margins didn't work in Xcode 8, now fixed in xCode 9. You have to go in redo your constraints and uncheck the box on the View inside all table view cells. This will then be consistent on all ios 10 and ios 11 devices.

enter image description here

I solved my problem by setting the header and footer height in Storyboard. Apparently, in Xcode 9 these are the default values when you create a UITableView

enter image description here

I tried to set them to 0, but 1 is the minimum and that solved the problem. Also, I checked how it behaves if the automatic is checked and it works as well.

Also, I don't know is it a bug or something, but I couldn't do it on existing table. I needed to delete it and drag it to UIViewController again.

If rashid's answer didn't work with setting the contentInsetAdjustmentBehavior to never then try the following:

self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0
self.tableView.estimatedSectionFooterHeight = 0

iOS 11 Floating TableView Header

Related