Reputation: 1739
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:
And what i got on iphone 6 plus:
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.
Upvotes: 27
Views: 6233
Reputation: 3804
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.
Upvotes: -1
Reputation: 8782
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)
Make sure view hierarchy should not be following way.(Subview might be but cut view must not).
Upvotes: 0
Reputation: 373
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.
Upvotes: 0
Reputation: 1050
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:
Upvotes: 19
Reputation: 1467
Try to remove the check Constrain to margins when adding constraints. Here take a look:
Constrain to margins is checked and its result
Now, after removing the constraints and re-adding the constraints with Constrain to margins unchecked, here is the result:
Upvotes: 53