Constraints and margins in xcode 6, margins reveal

2019-07-31 07:17发布

问题:

I'm trying to constrain a couple of views within a controller. I understand how to set spacing between views, and width/height for each view. I'm a little unsure about dynamic height and width, I'm assuming that it's the margin-locks duty to adjust the weight appropriately. Advice on this would be much appreciated.

Anyways, I'm trying to set a "Trailing Space to: Superview" constraint, which automatically sets to -16. See photo:

As you can see, I've selected margins for left right and top of view.

But once I launch the app in iPhone 6 Plus, the margins set are about -20 required. You can see my problem. Here's another photo, the view I'm talking about is green (you can see the whitespace on either side of it):

回答1:

The margins are a gap on the left and right to make things look neat. Due to the width of different devices, different devices have different sized margins. If you want to constrain your view to the edge you need to turn the margins off and set the constraints to 0. The margin on the 6 plus is 20, and I believe that the margins on the other devices are 16.

If there is no width constraint the view will stretch if you have a left and right margin.



回答2:

Check out the constrain to margins checkbox and set the values to 0

Please refer this posts about xcode

What is "Constrain to margin" in Storyboard in Xcode 6

Attribute Unavailable warning on iOS versions prior to 8.0