Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove section header separator in iOS 15

In iOS 15, UITableView adds a separator between a section header and the first cell:

enter image description here

How can I hide or remove that separator?

A few notes:

  1. The header is a custom view returned from tableView(_:viewForHeaderInSection:).
  2. When looking at the view debugger, I can see that the extra separator is actually a subview of the first cell, which now has a top and a bottom separator.
  3. Other than setting tableView.separatorInset to change the inset of cell separators, this is a completely standard table view with no customizations.
like image 950
Hesham Avatar asked Aug 21 '21 17:08

Hesham


3 Answers

Option 1: Maybe by using UITableViewCellSeparatorStyleNone with the table view and replacing the system background view of the cell with a custom view which only features a bottom line?

Option 2: Using hint from https://developer.apple.com/forums/thread/684706

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this
    if (@available(iOS 15.0, *)) {
        [self.tableview setSectionHeaderTopPadding:0.0f];
    }
#endif
}
like image 141
MacMark Avatar answered Oct 20 '22 04:10

MacMark


I had a similar issue, but it was due to the table header view suddenly showing as a separator on iOS 15. The only thing that worked for me was:

if #available(iOS 15.0, *)
{
    tableView.tableHeaderView = UIView()
}
like image 33
Ivan Andriollo Avatar answered Oct 20 '22 04:10

Ivan Andriollo


iOS 15, Swift 5

To remove the line between the section header and your first cell, you should set sectionHeaderTopPadding to zero while configuring your UITableView.

    if #available(iOS 15.0, *) {
        tableView.sectionHeaderTopPadding = 0.0
    }
like image 3
Sajjad Sarkoobi Avatar answered Oct 20 '22 02:10

Sajjad Sarkoobi