-1

I'm struggling with removing the white lines below each custom section header in an UITableView, as seen below. Any suggestions? I already use this in my TableView.

self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None

The above solves only the separators between the cells, not for the headers.

The only thing I have in my custom section header is

containerCellView.backgroundColor = UIColor(red: 24/255.0, green: 34/255.0, blue: 41/255.0, alpha: 100)

enter image description here

Recusiwe
  • 1,594
  • 4
  • 31
  • 54
  • Please show your code for header – AnthoPak Jun 28 '16 at 09:30
  • Refer http://stackoverflow.com/questions/925115/is-there-a-way-to-remove-the-separator-line-from-a-uitableview – Rince Thomas Jun 28 '16 at 09:34
  • Did you use a UITableViewCell for your header ? The code you provide in your edit is not responsible of showing a header. – AnthoPak Jun 28 '16 at 09:35
  • Until you give more code you'll get bad answers. – AnthoPak Jun 28 '16 at 09:42
  • 1
    Possible duplicate of [Want to remove the white line between Section and first cell in ios](http://stackoverflow.com/questions/33801330/want-to-remove-the-white-line-between-section-and-first-cell-in-ios) – Abhi Jun 28 '16 at 09:42

5 Answers5

2

Set heigth for header & footer to 0.01 it will solve your problem

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {

            return 0.01

    }
Rohit Pradhan
  • 3,867
  • 1
  • 21
  • 29
1

Put this line in viewDidLoad():

self.tableView.separatorColor = [UIColor clearColor];
Arpit Dongre
  • 1,683
  • 19
  • 30
Muthukumar
  • 62
  • 12
0

Use this code were you set your header

 headerView.layer.borderColor=[UIColor blackColor].CGColor;         
 headerView.layer.borderWidth=1.0f;
Nirav D
  • 71,513
  • 12
  • 161
  • 183
Birendra
  • 623
  • 1
  • 5
  • 17
0

I found out that it was the backgroundColor of my header cell that caused the problem.

self.backgroundColor = UIColor.blackColor()

Solved the problem in the custom header class

Recusiwe
  • 1,594
  • 4
  • 31
  • 54
0

I was able to reproduce similar issue on iPhone 7 Plus/iOS 12.1. I have a class conforming to UITableViewDelegate and tableView(_:heightForHeaderInSection:) is implemented like that:

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 100.0 // any float value
}

I added tableView(_:estimatedHeightForHeaderInSection:) to fix the problem:

func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
    return 100.0 // any float value
}

All code in this post was tested in Xcode 10.2.1. I used Swift 5.

Roman Podymov
  • 4,168
  • 4
  • 30
  • 57