NSAutoLayoutContraint for iPhone 6Plus - ios

Following is an image from iPhone6 having a simple view.
Constraint details are as follows.
But on iPhone 6 Plus, It starts getting margins from left & right.
Very easy to notice by looking at space before text 'Carrier' & space after battery icon in given images.
Question 1: Why do we add -16 as margin to leading and trailing space when adding a constraint to main/parent/super view?
Question 2: Why -16 margin works only for iPhone 6Plus & not for other phones?

Unselected Constrain to margin when you set your constraints

uncheck the "Constrain to margin" from constraint selection because this is a new feature of iOS8.

Related

Dealing with auto layout

I wasted few hours on constraints and I am still having issue.In
iPhone 6 screen, it is working perfectly but it is not working in iPhone 5/4. I set all views (image is background) to have fix W/H and hit auto add missing constraints.
As you can see on iPhone 5 its always pin to right, sometime to left. I Can't add anything its comes with error.
Any help? or some damn good tutorial for this :)
I made an example just for one row of your buttons, so they can be reused for other UI elements.
I put these constraints onto my buttons:
LEFT BUTTON:
left leading constraint
top leading constraint
height constraint
RIGHT BUTTON
right trailing constraint
top leading constraint
height constraint
And constraints related to both buttons:
(you need to select both buttons to be able to apply relation constraints)
spacing constraint between buttons
equal width of these buttons
In Interface Builder it looks like this:
And these layout is universal, so I chose some device sizes to present:
iPhone 5
iPhone 6
iPhone 6 Plus
... etc.

Constraints with Label on Image View

In my app I have a Image for my background with labels on top of it that are not moving correctly on the iPhone 6 Plus. I am having trouble with the constraints to make the labels move correctly with the image. With the screenshot I attached what constraints should each label have to keep it aligned with the image? Thank you!
screenshot
this shows the suggested constraints
constraints
Your constraints aim on left alignment. So that's way it only works on the size that you were building on, and other display sizes are not aligned properly.
Try to, at least these:
add left leading constraint between superview and textField
add right trailing constraint between button and superview
add spacing constraint between textfield and button
set exact width constraint of your button.
... then add suggested constraint or add your own to them.
Like this (iPhone 6):
View as iPhone 6 Plus:
View as iPad Portrait:
... etc
Is that exactly what you asked?

AutoLayout TableView issue with iPhone 6 and 6 Plus

I have 7 labels on a cell in TableView in Landscape mode and I have set the Top Space and Leading Space on each. My issue is it is working fine with iPhone 5 screen it fit well but I get and empty space with iPhone 6 and 6 Plus screen on the right place. How I can fix that with the constraint?
Example:
iPhone 5:
iPhone 6
Please check this youtube link https://www.youtube.com/watch?v=WTMpJJ9Ofm8
In this link it is showing how to arrange vertical spacing.
You can apply same logic to "Trailing Space to Container Margin" for equal spacing. By changing the multiplier value of the constraint you can change the spacing.

Why does Leading/Trailing space show as -16?

As I updated my Xcode from version 5 to 6 I saw a strange things in the storyboard. Here is one example:
What my requirement was - I wanted no space between my view and the container view.
What I did - I dragged the views left/right edge so that it meets the container margin. And then I put a horizontal spacing constraint.
Earlier the value used to be -
Leading/Trailing Space to:Superview Equals:0
Now after updating to Xcode 6 it always shows -
Leading/Trailing Space to:Superview Equals:-16.000000
Why does this happen?
That's container's margin. I think it applies the default margin to the edges. If you want to set up the Leading/Trailing Space to Superview constraint then you can do so.
If you have already created the constraint then you can select that constraint and uncheck Relative to margin
Please note the Relative to margin feature is only available on iOS >= 8, the app will crash (not sure but it should) on iOS < 8.
Try to uncheck "Relative to margin"

iOS autolayout changes leading and trailing space

I have some issues with auto layout, hopefully some of you can help me =).
I add a UIView to an empty view controller, like this:
Then I add constraints for leading and trailing space, like this:
Which results in this:
I can't understand why it sets them as equal to -16.0. If I change those values to 0, then Xcode complains about the width of the gray UIView.
When I run the app on iPhone 5 simulator, it looks fine:
However, when I run the app on iPhone 6 Plus simulator it adds white space on the left and on the right:
I don't want the gray UIView to have any space from the left of from the right no matter how big the screen is. How can I fix it? Thanks!
Double click the constraint and open it. There select first or second item and deselect "Relative to margin". Then set your constant as 0.
Xcode is showing -16 because it is calculating space with respect to a margin and not the edges.
Check following link for more info on margins. Editing Auto Layout Constraints
You can clear all existing constraints on the view,and in Any*Any mode, add constraints for all 4 space to superview, which are Leading, Trailing, Top, Bottom. Then it will have the equal width with the screen no matter how big the screen is.

Resources