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.
Auto Layout is a constraint-based layout system. It allows developers to create an adaptive interface that responds appropriately to changes in screen size and device orientation.
Auto Layout constraints allow us to create views that dynamically adjust to different size classes and positions. The constraints will make sure that your views adjust to any size changes without having to manually update frames or positions.
Together, an interface's constraints describe the ways views can be laid out to dynamically fit any screen or window geometry. In Cocoa and Cocoa Touch, a well-defined interface layout consists of constraints that are satisfiable and sufficient. Each individual constraint refers to either one or two views.
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:
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With