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?
Swift:
Arg!!! After playing around either doing this in your
Cell
subclass:or setting the
cell.layoutMargins = UIEdgeInsetsZero;
fixed it for me.For me the simple line did the job
This is my solution. This applies to the custom cell subclass, just add them both to the subclass.
2.
And it is convenient that you can customize the position of the separator without asking your designer to draw one for you..........
This worked perfectly for me in iOS 8 and iOS 9.
For OBJ-C
I believe this is the same question that I asked here: Remove SeparatorInset on iOS 8 UITableView for XCode 6 iPhone Simulator
In iOS 8, there is one new property for all the objects inherit from
UIView
. So, the solution to set theSeparatorInset
in iOS 7.x will not be able to remove the white space you see on the UITableView in iOS 8.The new property is called "layoutMargins".
The solution:-
If you set
cell.layoutMargins = UIEdgeInsetsZero;
without checking if thelayoutMargins
exists, the app will crash on iOS 7.x. So, the best way would be checking if thelayoutMargins
exists first beforesetLayoutMargins:UIEdgeInsetsZero
.