How to change the extra padding above UITableView
section headers that has started to appear in iOS 15?
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
.
For applying changes everywhere in app
if #available(iOS 15.0, *) {
UITableView.appearance().sectionHeaderTopPadding = 0.0
}
preferably in AppDelegate
.
Put this in the main didFinishLaunchingWithOptions to fix it globally:
if (@available(iOS 15.0, *))
{
UITableView.appearance.sectionHeaderTopPadding = 0;
}
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
}
A global way for obj-c:
if (@available(iOS 15.0, *)) {
[[UITableView appearance] setSectionHeaderTopPadding:0.0f];
}
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