Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change tableView separator insets

I'm incurred in a little problem customizing my cell;

enter image description here

as you can see the separator line do not reach the left border of the cell, and a I'd like to do it. I found these:

  • Separator lines for UITableViewCellStyleSubtitle cells not taking the full width
  • iOS 8 UITableView separator inset 0 not working

Can anyone help me to translate in swift code?

like image 906
Fabio Cenni Avatar asked Aug 24 '15 09:08

Fabio Cenni


1 Answers

Swift 3:

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    if (cell.responds(to: #selector(setter: UITableViewCell.separatorInset))) {
        cell.separatorInset = UIEdgeInsets.zero
    }

    if (cell.responds(to: #selector(setter: UIView.preservesSuperviewLayoutMargins))) {
        cell.preservesSuperviewLayoutMargins = false
    }

    if (cell.responds(to: #selector(setter: UIView.layoutMargins))) {
        cell.layoutMargins = UIEdgeInsets.zero
    }
}
like image 98
Lukas Batteau Avatar answered Nov 03 '22 01:11

Lukas Batteau