I have an app where the UITableView
's separator inset is set to custom values - Right 0
, Left 0
. This works perfectly in iOS 7.x
, however in iOS 8.0
I see that the separator inset is set to the default of 15
on the right. Even though in the xib files it set to 0
, it still shows up incorrectly.
How do I remove the UITableViewCell
separator margins?
I made it work by doing this:
Just add below code can solve this program.
Good luck to you!
For iOS 9 you need to add:
For more details please refer to question.
Most answers are showing separator insets and layout margins being set over a variety of methods (i.e.,
viewDidLayoutSubviews
,willDisplayCell
, etc) for cells and tableviews, but I've found that just putting these incellForRowAtIndexPath
works great. Seems like the cleanest way.In Swift it's slightly more annoying because
layoutMargins
is a property, so you have to override the getter and setter.This will effectively make
layoutMargins
readonly, which in my case is fine.This is the code that's working for me, in Swift:
This seems the cleanest to me (for now), as all the cell/tableView edge/margin adjustments are done in the
tableView:willDisplayCell:forRowAtIndexPath:
method, without cramming unneccessary code intotableView:cellForRowAtIndexPath:
.Btw, I'm only setting the cell's left separatorInset/layoutMargins, because in this case I don't want to screw up my constraints that I have set up in my cell.
Code updated to Swift 2.2 :