Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected result for autolayout on iphone 6 plus

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.

like image 561
Horst Avatar asked Sep 22 '14 10:09

Horst


People also ask

What is IOS Autolayout?

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.

What is Autolayout in Swift?

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.

What are IOS constraints?

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.


2 Answers

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 marginsresult

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

Constrain to margins uncheckedresult without Constrain to margins

like image 191
Sharon Nathaniel Avatar answered Oct 17 '22 16:10

Sharon Nathaniel


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 solutionSolution stepAfter applying solution

like image 19
pimguilherme Avatar answered Oct 17 '22 17:10

pimguilherme