iosuitableviewuitableviewsectionheader

Separator insets for table section header


I have an UITableView (style = UITableView.Style.plain) with rather simple cells. In IB I set cell's separator inset as custom:

enter image description here

Also, I set table section header as follows:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    let label = UILabel()
    label.textAlignment = .center
    label.backgroundColor = .white
    label.text = "My table section"
    return label
}

The result is:

enter image description here

I want to remove separator between "My table section" and "cell 0". How do I fix it?


Solution

  • This is the default separator of the tableview if you don't want it you can set it to none.

    enter image description here

    And if you want separators under the cell you have to make one by yourself. Just add a view in your cell under the label and give its constraints like leading-trailing top-bottom and height(how much thick separator you want in my opinion maybe 1.5), that should do the job.