27

I've added a uiview on a view controller(VC), trying to set it's width is equals to VC's view's width.

What I set and expected: xcode setting and expected result

And what i got on iphone 6 plus: what i got on ip6+

I've tried to change the constants of leading space and trailing space and no help. Is there any special for iphone 6+ autolayout?

The view setting here is "Any width x Regular height"

-------Added Dec 2016 To people who is confused by this case like me: There is a layout margin property in UIView, which is an UIEdgeInsets(8,8,8,8). It is something like css padding.

When the edge of your view is close to the edge of the superview and the preservesSuperviewLayoutMargins property is true, the actual layout margins may be increased to prevent content from overlapping the superview’s margins.

The default margins are eight points on each side.

If the view is a view controller’s root view, the system sets and manages the margins. The top and bottom margins are set to zero points. The side margins vary depending on the current size class, but can be either 16 or 20 points. You cannot change these margins.

Horst
  • 1,733
  • 15
  • 20

5 Answers5

53

Try to remove the check Constrain to margins when adding constraints. Here take a look:

Constrain to margins is checked and its result

Constrain to margins result

Now, after removing the constraints and re-adding the constraints with Constrain to margins unchecked, here is the result:

Constrain to margins unchecked result without Constrain to margins

Sharon Nathaniel
  • 1,467
  • 20
  • 28
19

Sharon's answer works wonderfully, but you don't have to delete the existing constraints to solve the problem. You may edit existing constraints removing the extraneous margin:

Before applying solution Solution step After applying solution

pimguilherme
  • 1,050
  • 11
  • 15
  • I'm having this same probem. How did you add Horizontal Space Constraint? – 4thSpace Mar 27 '15 at 16:56
  • Are you familiar with creating autolayout constraints? It's just a matter of creating a regular constraint and unchecking the "Relative to margin" option. – pimguilherme Mar 27 '15 at 17:29
  • @4thSpace : when you uncheck the margin, it will automatically change from a Leading constraint to a Horizontal Constraint. – Mike Burba Aug 18 '15 at 12:01
0

Editing existing constraints to remove the extraneous margin will not work. You have to delete the existing constraints and add new ones keeping constraints to margin unselected.

bhoomi
  • 373
  • 1
  • 4
  • 11
0

I faced same issue for my "Done" button. The issue was my View (Done Button) was in base View hierarchy so i bring view back in root view (view controller's view). and set constraints accordingly.

My case set constraints Pin-> Uncheck Constraints to Margin -> Bottom,Leading,Trailing (Constraints value=0)

enter image description here

Make sure view hierarchy should not be following way.(Subview might be but cut view must not).

enter image description here

Avijit Nagare
  • 8,482
  • 7
  • 39
  • 68
-1

I had this bug in the iPhone 6 plus simulator. But in the 6 plus device this bug didn't happen. This could be just a bug with 6 plus simulators.

coolcool1994
  • 3,704
  • 4
  • 39
  • 43