stuck in concept of auto layout in Xcode 6.4 - ios

I just started to learn auto layout.
I have switched off the Use Size Classes.
I make there UILabels which is shown in the image and their constraints also. I want to look similar in 4s,5s,6 and 6Plus.
But it is working fine on 4s and 5s but distorts in 6 and 6Plus.
Why this is happening and how can I resolve this.
My StoryBoard with constraints:
Output iN 5s
Output IN 6 and 6Plus

Assuming that the way labels are placed in 5s is what you are really looking for, place the constraints as follows :
Pin width of all labels equally.
Pin Height of all labels
Pin vertical position of all labels from top margin equally.
Now, as for the problem, add the constraints as follows for horizontal placement of labels :
[leading margin--0--label1--40--label2--<=20--label3--Trailing margin]
Adding the horizontal constraints should work for all sizes.

This happens because none of your constraints is hooked to the leading/trailing layout guide. What you'll want to do is to attach labels 1 & 3 to the "sides" of the view, and then attaching label 2's constraints accordingly. (I would recommend adding a center horizontally constraint, but it can be achieved by different ways).

Related

xcode story board doesn't align for iphone 5

When I try on iPhone 6 or higher it works fine, but for 5 it simply doesn't align correctly. I haven't set any size for the controller.
This is expected, you need to apply autolayout constrains on the subviews,
read here auto layout and here constraints
By this they will be centered on all devices or look like the way you define the constraints.

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?

Auto Layout and setting constraints is changing the sizes of the buttons in my app

I'm trying to resize my app by using constraints and auto layout so that it can fix on every iPhone screen, the only problem I'm having is that the size of the buttons in my app are getting smaller as i move to the 4 inch and 3.5 inch. Im working in inferred view, how can i fix this problem?
Try to use leading, top, trailing and bottom constraints instead of using height and width. If problem persists share the screenshots along with the constraints.

Need to fix autolayout issues with only UIButton's and UILabels

Currently i am trying to use AutoLayout on my iOS app in xcode 6. The storyboard I am using consists of only UIButton and UILabel elements, which i would like to resize and fit based on the device. Everything works on the iphone 6 Plus and 6 but when I get to the 5S or 5 things get weird. I can't use size classes necessarily due to both 5s and 6/6P using compact width regular height. IS there a way to fix this?
all images can be found here
Yes! With autolayout there's always a way.
From those pictures it looks like you may have a vertical constraint on the "play" button that is attached to the top of the view. Try putting that constraint on the "How Long" label. That way the button position will be relative to the title instead of the whole screen.
Check to see that you have the following constraints :
Center all buttons and labels horizontally in the container (note,
this is 3 different constraints you need to set). You can select
all 3 at once and from the Align menu center them horizontally in container.
Constrain How Long to Top Layout Guide (Top Space to Top Layout Guide)
Constrain Play to How Long (pin vertical spacing)
Constrain Leaderboard to Play (pin vertical spacing)
Depending on how you want Leaderboard to float you may want to pin it to the Bottom Layout Guide instead of to play. The buttons and labels will then move according to your constraints.

Autolayout Rendering inconsistently across devices

I have a series of views each containing a scrollview wrapping various subviews i.e. Collection views, Labels, imagview. I am using auto layout for the first time and some views render fine on some devices but not on others, I have attached previews of views on iPhone 4s, 5, and 6.
In particular I am not sure how the alignment of the History views appears off centre in iPhone 5 and 4 but fine in 6, and the collection view in iPhone 6 appears cut sort on the right side but not for iPhone 5,4, and lastly how the blue image with label 'Image Title' on top of the zoomable image on iPhone 4s appears to be cut short. I would of thought a error in autolayout would of been consistent across devices ?
Any input appreciated.
It looks like you're setting absolute widths on some elements. Instead you should be setting distance to the parent UIView's edges. I.e. trailing/leading space to container.
Try to give consistent constraints. Looks like you are just doing leading and top space to superview and maybe you are adding width and height constraints to avoid misplaced views. Try to think like you are doing autoresizing masks before autolayouts. Either try to keep ratio or expand with the container with trailing and bottom space constraints.

Resources