Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extra padding above table view headers in iOS 15

How to change the extra padding above UITableView section headers that has started to appear in iOS 15?

like image 374
Jakub Truhlář Avatar asked Jun 27 '21 20:06

Jakub Truhlář


5 Answers

Since iOS 15, UITableView contains a new property called sectionHeaderTopPadding which specifies the amount of padding above each section header.

tableView.sectionHeaderTopPadding = 0.0

Note: This applies only to the UITableView.Style.plain.

like image 102
Jakub Truhlář Avatar answered Oct 23 '22 08:10

Jakub Truhlář


For applying changes everywhere in app

if #available(iOS 15.0, *) {
    UITableView.appearance().sectionHeaderTopPadding = 0.0
}

preferably in AppDelegate.

like image 25
Hassy Avatar answered Oct 23 '22 08:10

Hassy


Put this in the main didFinishLaunchingWithOptions to fix it globally:

if (@available(iOS 15.0, *))
{
    UITableView.appearance.sectionHeaderTopPadding = 0;
}
like image 29
Aace Avatar answered Oct 23 '22 09:10

Aace


This is the new Instance Property of UITableView in iOS 15. https://developer.apple.com/documentation/uikit/uitableview/3750914-sectionheadertoppadding

sectionHeaderTopPadding which specifies the amount of padding above each section header.

To remove the padding use below code

if #available(iOS 15.0, *) {
    self.tableView.sectionHeaderTopPadding = 0.0 
}

To remove the padding from everywhere in the app, use below code in AppDelegate

if #available(iOS 15.0, *) {
    UITableView.appearance().sectionHeaderTopPadding = 0.0
}
like image 11
Ashu Avatar answered Oct 23 '22 07:10

Ashu


A global way for obj-c:

if (@available(iOS 15.0, *)) {
    [[UITableView appearance] setSectionHeaderTopPadding:0.0f];
}
like image 10
Medhi Avatar answered Oct 23 '22 08:10

Medhi