Constraints for iPhone 6+ - ios

I have three buttons on a screen and I am adding them to the bottom half of the screen. I am using size classes and want them same on all iPhone portrait orientations. I am adding constraints separately for Compact Width | Regular height and Compact Width | Any Height. But for one resolution the UI is not setted right and thats either iPhone 6+ or iPhone 4s. Anybody have any idea what I am doing wrong and how to design for all iPhone resolutions using size classes. It appears I have arrived at a deadlock.
Thanks in advance.

You are using size classes so have to set vertical and horizontal spacing. In Universal Storyboard there are option "Any Width Any height" and "add new alignment constraints"
See this link.
https://www.youtube.com/watch?v=G53PuA_TlXk

Related

How to set different size for uibutton in storyboard for iphone 5s and iphone X?

All iPhone devices from iPhone SE to iPhone XSMax fall under same size class of compact width and regular height in Portrait mode. Then how can we add different size for UIButton in storyboard that can vary for iPhone 5s, iPhone 6 and iPhone X?
How can we use size classes for iPhones in portrait mode? Also how can we use different font sizes for different devices?
I tried to use vary for traits in storyboard but was unsuccessful to set different heights for a UIButton in different iPhone devices.
I want to set Button to be of height 30 in iPhone 4s and I want that button to grow as the device height increases and font size also should vary accordingly. Setting button's height proportional super view's height didn't yield me desired results as there are other UIElements in the storyboard.
This can be done in a lot of different ways. You could for example
Use proportional height constraints
Not use height constraints and only constrain the distance to the screen / other elements
As the screen grows, the distance to the screen edge will stay the same, resulting in a bigger button
Set different heights for different screen sizes via code
You could wrap this into a NSLayoutConstraint subclass that has #IBInspectable properties, allowing you to set everything up using the Interface Builder
I think you should first think about your design again. Fixed heights usually break as soon as there are new iPhone sizes. Because of that, you should probably try to not have fixed heights for different phones and instead use equal distances to other elements or proportional constraints.
In my opinion most fixed heights are unnecessary and I'd consider them a code-smell.

Xcode Auto-Layout Issue for smaller screen sizes

All screen sizes display the app as expected except 3.5 Inches, that is always off by a long shot. What can I do to prevent this?
In Interface Builder, you'll want to set constraints for compact screen sizes. At the bottom, you'll see this:
Change that to Compact Height x Compact width and set constraints for that screen size.

Swift Xcode auto layout constraints only target iphone 6 plus and ipad

The auto layout "picker" looks like the image bellow:
But what if I only want to target iphone 6 plus and Ipad?
I use the constraints compact width | any height in order to only target 3.5 - 4.7" displays.
But what should I use in order to only target iphone 6 plus / ipad? - The any width | any height do target them but would that not also overwrite the rules set in compact width | any height ?
What I want to do is to increase spacing between three labels when the app runs on a iphone 6 plus or ipad. Also to note, my app only runs in portrait mode if that matters.
thanks in advance,
You shouldn't categorize autolayout via device, but rather by class sizes. This was a HUGE emphasis this year at WWDC due to the new iOS 9 iPad multitasking feature discussed at the keynote.
I recommend trying the following idea for your layout. Note this is just a visual interpretation of what you need to implement in IB.
All three labels have equal width constraint
|---[first label, maxwidth = x]--[second label]--[third label]---|
This will make all three labels have the same width and be evenly spaced across. This approach helps with all class sizes of compact width | compact height, etc. If you need help finding a way to do even spacing between, trying adding filler views:
|[uiview][first label, maxwidth = x][uiview][second label][uiview][third label][uiview]|
Each [uiview] in this case will have the same width as well with a background color of clear this way the margining between the labels will be even and these views aren't "seen" but help with autolayout.
If you need help with this auto layout implementation please let me know in the comments.

Centering in Storyboard

I am a little bit confused by Xcode 6 Storyboard.
The auto layout seems to be a very powerful tool to build UI for different devices. However, no matter what kinds of layout I chose (compact or any height/width) or even uncheck the "Use auto layout" and "Use size classes", what I mapped in the storyboard view always looks different when I am testing (using an iPhone 6).
For example if I left a UIButton at the center of the storyboard, it will be a little right down away from center when appears on my iPhone 6.
Could anyone please give me some help on this. Maybe just for iPhone6 instead of different devices. Thank you very much.
If you simply want to center an UI element check both Horizontal Center in Container and Vertical Center in Container in the storyboard constraints alignment popover.
The reason, you are having this issue is the mis-matched stimulator size. For example, the apple standard for iPhone 6 is a frame of 400 x 600 pt, meaning 2:3. So,
First, turn on the auto Layout and size classes. Then change "wAny hAny" to "compact hAny".
If, you change the Stimulated Size now, you will se the width as 400 and height as 600.
After this you need to add the UIButton at the centre and even without adding any constrain, you will see your button to be centered in the frame.

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