Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

ios - XCode 6.3 adding margins to tableviewcell

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:

enter image description here

Now, everything in the cell seems to have additional margins that I have no idea where they came from.

enter image description here

Note that these view's widths are not altered in any way in code and the right and left are constrained as below:

enter image description here

Also note that I am using tableView.separatorStyle = .None. I add this fact because for some reason in one of my tableViews 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: enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Look carefully at this screen shot of the Size inspector for a leading constraint:

enter image description here

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...