Did XCode 6.3 / Swift 1.2 add additional margins to a UITableViewCell's contentView? Prior to updating, I had a custom UIView that extended all the way across the screen in my cells. Example:
Now, everything in the cell seems to have additional margins that I have no idea where they came from.
Note that these view's widths are not altered in any way in code and the right and left are constrained as below:
Also note that I am using tableView.separatorStyle = .None
. I add this fact because for some reason in one of my tableView
s that has the default separator, it doesn't appear to add these additional margins.
Does anyone know if they did some weird change in XCode 6.3? This behavior occurred directly after updating.
Edit:
Look carefully at this screen shot of the Size inspector for a leading constraint:
See how "Relative to margin" is checked? That's your problem. If the margin changes, your left edge changes. Uncheck that menu item and then change the Constant to zero. Do that for the trailing constraint too, and your problems will be over.
Now let's address the deeper issue: what changed? You are absolutely right, something did. I believe they fixed a bug, and you got caught in the fix. Logging shows me that the cell's preservesSuperviewLayoutMargins
is true
and that the table's margins are 0,16,0,16
. This is true even on iOS 8.2, so the effective margins on iOS 8.2 should have been 16. But they were 8, as if preservesSuperviewLayoutMargins
were false
. But in iOS 8.3, this setting is obeyed properly — with the result that you have observed.
Thus, another way to fix the problem would have been to leave your constraints as they are, but to set each cell's preservesSuperviewLayoutMargins
to false
in cellForRowAtIndexPath:
. This works equally well to make the outcome identical in both systems.
EDIT Good news: it looks like this change is reverted in iOS 9. Thus, without change, your cells would look the same in iOS 9 as they did in iOS 8.2 and before.
来源:https://stackoverflow.com/questions/29712191/xcode-6-3-adding-margins-to-tableviewcell