Vaska Kot Vaska Kot - 1 month ago 6
iOS Question

UITableViewCell separator insets don't work

I set separator insets to 0 in my storyboard but when I runs the code, the inset is not 0 . Is it the bug of iOS? Is it any workaround here? (I'm new in iOS development)

Answer

Add the willDisplayCell function of UITableViewDelegate to your code and set the separatorInset and layoutMargins of your cell:

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
      cell.separatorInset = UIEdgeInsetsZero
      cell.layoutMargins = UIEdgeInsetsZero
}