1

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:

Adding New Constraints to view

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):

Application running with margins set on green view

Rob
  • 631
  • 1
  • 7
  • 20

2 Answers2

3

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.

James Snook
  • 4,063
  • 2
  • 18
  • 30
  • Thanks, that's super helpful. Do you know how to set these values programatically? I can't have a view cut off for the 6 and not the plus – Rob Sep 29 '14 at 19:26
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

Community
  • 1
  • 1
Manjunath Siddappa
  • 2,126
  • 2
  • 21
  • 40