Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 9 UITableView separators insets (significant left margin)

I have a problem with separators between UITableViewCells in UITableView on iOS 9. They have the significant left margin. I already have code for removing spacing introduced by iOS 8 but it doesn't work with iOS 9. It looks like they added something else. I suppose it might be connected with layoutMarginsGuide but I haven't figured it out yet. Does anyone had a similar problem and found out the solution?

like image 848
Julian Avatar asked Jul 21 '15 10:07

Julian


2 Answers

Okay, I have found out the solution. The only thing required for that is to set on the presenting instance of UITableView that flag cellLayoutMarginsFollowReadableWidth

myTableView.cellLayoutMarginsFollowReadableWidth = NO; 

I wanted to find some reference in the documentation but it looks like it is not ready yet, only mentioned on diff page.

As the flag was introduced in iOS 9 for the backward compatibility you should add a check before trying to set it:

if([myTableView respondsToSelector:@selector(setCellLayoutMarginsFollowReadableWidth:)]) {     myTableView.cellLayoutMarginsFollowReadableWidth = NO; } 

For Swift 2.0 you can use #available to check iOS version.

if #available(iOS 9, *) {     myTableView.cellLayoutMarginsFollowReadableWidth = false } 

Moreover you need to compile it with Xcode 7 or above.

EDIT

Please keep in mind that this is the only required fix if your separators looked "fine" up to iOS 8, otherwise you need to change a bit more. You can find info how to do this already on SO.

like image 59
Julian Avatar answered Oct 30 '22 06:10

Julian


If you want to do it in interface builder. The default separator inset is Automatic. Change it to custom by selecting the dropdown.

enter image description here

like image 24
ArunGJ Avatar answered Oct 30 '22 06:10

ArunGJ