I have several custom UITableViewCells in my app, mostly defined by nibs. When moving to iOS 8 and Xcode 6 the margins on the left and right are incorrect. These cells are often interspersed in a table view with default cells.
I made a sample project, here is the margin issue I'm talking about:
The only thing I've been able to find that relates to this is the new property layoutMargins
. For UITableViewCells its value seems to change depending on the device the app is running on:
iPhone 6 and below - layoutMargin: {8, 16, 8, 16}
iPhone 6 Plus - layoutMargin: {8, 20, 8, 20}
This seems to line up with the margins I'm seeing on the standard cells. However, the content for my custom cells is inside the cells contentView
, which has the standard UIView layoutMargin
of {8, 8, 8, 8}
. This means any auto layout constraints that are bound to the Container Margin are adding the incorrect spacing.
The only way I've found to fix this is by adding the following in cellForRowAtIndexPath:
cell.contentView.layoutMargins = cell.layoutMargins;
This doesn't seem like a very good solution going forward (especially since I'd need to wrap it in checks for iOS8 to maintain compatibility).
Does anyone have any ideas? I feel like I must be missing something.