AutoLayout (Y-Constraints for different iPhones) - ios

The problem I'm having is that the y-size of the iPhone 4 is much smaller than the y-size of the iPhone 5 & 6(+).
If I want to support both devices I can use almost only half of the screen of the iPhone 6(+) because if I use the whole screen and add y-constraints to the top and bottom it does not work for the iPhone 4 since the constraint lengths are way too big.
How can I use the whole screen of the iPhone 6 and similarily use the full screen of the iPhone 4? Is there anything I'm missing?
I watched a tutorial but the tutor only uses center-y as constraint.

why is it necessary to set a bottom y-constraint?
otherwise, you could put everything inside a scrollview (with scroll enabled and with all the y-constraints you want at top and bottom between the scroll view and the main view), and inside the scroll view you can put the previous top and bottom y-constraints
if you use size-classes, you should be able to create a specific layout for iPhone 4 and another one for iPhone 5-6+

Related

Label not pining to the right of a tableview cell

I'm trying to pin the points label to the right of a tableview cell.
Problem is when I pin to the bottom, top and right and then I change the size of the screen, the pin doesn't work.
I have been watching loads of videos and articles about auto layout, and I really couldn't find out why it is not working.
This is how I setup the Label 90 on a iPhone 8 screen
So to achieve this I set these constraints
But when I change to an iPhone 8 Plus screen, this is the result, the label 90 was dragged to the left
And when I go back to iPhone 8 screen, the label is not even showing on the screen
Your constraints seems to be right to see on all devices as you are keeping left (trailing) to 6, which is constant and will work same on all.
Please run on simulator, preview will only works better on same device to same preview, not otherwise as it doesn't do proper constraint like in run time.
Most important is to use UI debugger if any view is not placed well to get better idea where exactly the problem is.
Thanks.

Constrains look different on my iPhone 5S

This is my first post. I just started coding. I want to make my first simple app. I own an iPhone 5S and when I add constrains in compact width / compact width & regular height(in XCode), it shows it right on the iPhone 6S plus simulator. When I try it on my iPhone it just looks weird. I know the sizes of the iPhones are different, but how can I correct this? Now, if I code in compact width / compact width & regular height, it feels like I am coding for an iPhone 6...
I hope someone can help me.
Here is the Storyboard:
I use compact/regular size classes for portrait, and any/compact for landscape, for those two phones you mention (actually, for all of the phones).
And, (squinting at your constraints in the tiny pic), it looks to me like the constraints are "wrong" (not optimal, at least). You've got the button pinned 550 down and 280 across from the edges, which won't look right for smaller devices.
Try aligning the button to horiz and vertical centers, and it will look right everywhere.
Or pin ONE of the edges of the button, and ONE of the top/bottom edges of the button, to the layout margins on one corner. Then it will look right on all devices.
Instead of removing the trailing and bottom constraints, as #Kevin suggests, set both of their constants to 0 (or whatever's reasonable), and make them greater than or equal, not equal.
For the constraints to appear fine for different screen sizes, one possible way is to add the required constraints to your button or label or any other component and have a preview look at it in the assistant editor section.(Click on assistant editor and in the split screen that comes up, find the Automatic section and within it the preview option)This helps to view the layout of your app for different screen sizes. This helps to manage your auto layout issues by a good extent.

constraints doesnt keep it in the middle

When I add an image and constraint it to remain in the top-half center of the screen; I would like it to work with all iPhones except it doesnt,.the problem is it only works with iPhone 4 portrait and landscape that I have but when I change the iPhone to iPhone 6 it doest stay in the middle, does anyone know why?
To geta an element in the middle of the screen here are a few tips:
Ensure you drag the object in to the middle of the screen (Horizontally). You will notice guideline's appear up the screen.
Set the constraints on the item which include 'Set Horizontally in container' & Set a top constraint only (You may want a height wand width also, experiment with this.
For an image make sure that you have set your fill property for your application. (Aspect Fill etc)
A good tip to get used to auto layout is to set your view controller to iPhone 4 and design on that (With constraints of course)
Auto-Constraints are rubbish, create them yourself!

Constraints to take care of different iPhone/iPad sizes for images xcode 7 beta 4

I'm new to iOS development, so setting constraints for objects on the storyboard in Xcode has been difficult for me.
As this picture below shows, I have 3 borders for buttons I created in sketch so they are all images, each of them inside of a image view:
I tried adding constraints by pinning all three images to the left, right and below themselves but I got errors for it and it did not come out right at all on the simulators. All of the images are in aspect fill mode, and I have the view in the size of an iPhone 4 when I put the images in the storyboard. Here's an example of what it looks like in the iPhone 6 simulator without any constraints:
What are the constraints I need so that it looks okay for all iPhone and iPad sizes and looks like it does in the storyboard? And landscape mode will not be a part of this application, so that will not need to be accounted for.
You can also use button 1 equal width constraint
and button 2 equal width constraint
For more details http://www.raywenderlich.com/83129/beginning-auto-layout-tutorial-swift-part-1
Which is your requirement???

How to handle iPhone 4s, 5 and 6 screen size, and make all the contents look the same across al the devices

I am using Xcode 6.1 and in one of the views I have, contains many labels. However, these labels look different in each different devices. Although I have add constraints to all the labels, but still facing the same issue.
How can I get the same view layout across all devices?
How can I make the width and height for each label is flexible, depends on the screen size?
Do I need to design different xib for each device?
The following images showing the result am getting, with auto resize enabled, and constants been added.
on iPhone 6
on iPhone 5
on iPhone iOS 7.1
We have provided with a simple solution . Using Aspect ratio constraint we can get a relative look in all device screens.
I had the same issue and I found this >>
http://mathewsanders.com/designing-adaptive-layouts-for-iphone-6-plus/
So when designing for lowest to highest screen resolution we can't set a specific width and height for all controls as it may look weird. So using this constraint we can have a relative look for all screens.
If you don't want to use constraints or you want to keep the same width & height , you can add scrollview to hold all controls. For that you can set a resizing frame for scrollview with fixed content size .
To solve this...
1) Go to xib file and uncheck the Auto layout
2) Then set the autosizing manually in the following manner for each and every subview.
Use self.view.bounds.size.width to get the width of screen, then use relative value to initialize all labels.
One soultion is that you can Design a story board for each screen size like one for iphone 5, one for iphone 6 and one for iphone 6+ and in your AppDelegate method "didFinishLaunchingWithOptions" you can get the screen size and popup corresponding storyboard
in this wasy you can set different constraints according to different screen size

Resources