Xcode Layout constraints: selecting divisions - ios

I want to have two different layouts. The first layout must be applied to iPhone-3.5inch, and the second one to all the other device sizes. However, the layout I set for the compact width/compact height does not seem to take over the other layout even when I test with an iPhone-3.5inch. How can I make the first one be applied to a small device, while the other to the bigger ones?

according to documentation compact width/compact height is size class for All iPhone models except iPhone 6Plus In landscape mode.
If you want to know whether the device is with 3.5inch screen you must do it in code.

Related

Choosing appropriate screen size to work with

I have got rather general question about making Adaptive Layout in iOS App.
When creating new project in Xcode you have ability to choose with which screen size you can start working:
I have noticed that if you place a square UIView on iPhone SE screen and then connect Leading, Trailing, Top and Bottom constraints - this view displays correctly on every other screen. But if you perform same actions on iPhone X, then this same shape would be corrupted on smaller screens.
So, my questions are:
Which iPhone screen size to choose, when starting making iOS app in
order not to face headaches with constraints on other screens and to
make pixel perfect UI?
If I receive design prepared for iPhone X screen, can I prepare it
firstly for iPhone SE screen and will it be displayed correctly on
bigger screens in this case?
What are screen sizes you use in your projects most frequently?
Actually there is no difference in choosing which 1 , what you need is to make your thoughts when making constraints to be generic , and that means every static width/height will appear similar in all devices , and every proportional 1 will look according to the device size , personally i like to use iphone 5 ( please forget about iphone 4 or you'll have to make the main view a scrollview because of the very small height of that device ) , also you can toggle the device to see how the constraints you set ( in the choosen 1 ) are look in the other device
You don't need to 'choose' a size. This is just a display setting and you can change it at any time to preview your layout on different devices.
You need to make your constrains in a logical way that will naturally adapt when change screen sizes.

Size Classes & Plus Phone

So all phones have compact width/regular height in portrait. Plus phones have regular width/compact height in landscape while others have compact width/compact height.
So the only in LANDSCAPE orientation you can distinguish a plus model phone.
Question
Is there a way to distinguish a plus model phone in portrait orientation?
without checking for:
Screen resolution
Screen scale
Device strings
NOTE:
Checking for screen resolution/scale, device strings are plausible, however trying to stay away from those. For example, Apple had to put Contact Icons for Favorites for iPhone Plus in Portrait. So there has to be a formal way to do this?
You are getting it wrong. The main purpose to make the adaptive layout is it can adapt to any screen size irrespective of device.
You should not think about these devices screen size while making layouts. You should be thinking of size classes.
If your layout can work in above size classes than it should work in respective phones. Also if you are looking for orientation but your app support the multitasking than your layout might not work with that.
Ideally, Your app should have layout that can work in any screen size because apple is releasing new devices with different screen sizes so your app should be compatible and work in every layout.
But that is ideal world. You can handle most of your layout with size classes. In some cases you need to handle the special scenarios.

Xcode 7 to 8: Size Classes

I have developed an app with Xcode 7 and I placed all my views for all iPhones in portrait. Now using Xcode 8 I want update the constraints for supporting iPads in portrait. How I am supposed to to that? Copy/Paste views and start from scratch? I can't see any other solution.
PS. Note that views for iPhone 7 Plus to iPhone 4S appears fine.
No need of copying the views. The Xcode SizeClasses aids you in designing the app for various devices.
I suppose you may have used the Any Width Any Height (wAny hAny) or the Compact Width Regular Height (wC hR) to design the portrait orientation screens. Now use the Regular Width Regular Height (wR hR) size class to design the iPad screens. Size classes will automatically switch sensing the device rather than programatically selecting one among the two storyBoards designed for iPhones and iPads.
Select the wR-hR size class. Select your view in the Document Outlinein the storyBoard. In the Attribute Inspector install the view for the current size class (wR hR). the view will appear in the storyboard scene. Set the suitable constraints and you are good to go.
PS: Of course you must set the constraints again unless you have designed the iPhone screens in wAny hAny size class. If so that works in iPads too and you needn't work on any other size class.

different ui items alignment for tablet

I'm new to ios(android dev). I'm using storyboard, and autolayout.
To optimize application for tablet, i used sizes in storyboard regular width regular height.
I want to align ui items on ipad different than on iphone mode. For example, i have a table of textfields that occupy full width on iphone. On ipad i want to place two or three textfields in one cell. How can i make different ui implemetation for ipad, so the logic shoudl stay the same.
I watched https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/LayoutandAppearance.html#//apple_ref/doc/uid/TP40006556-CH54-SW1
But there is no answer there.
Jenya Kirmiza,
Size Class is what you want :) Size classes were introduced with iOS8 in order to avoid the multiple storyboards for universal applications and yet provide an easy way for the developer to design differrent UI for differrent Devices :)
I expect you to know SizeClasses, In case you are not aware each device in its various orientation falls to one of the sizeClass defined by Apple.
One thing important to note here is that iPad in its both the orientation falls to Regular x Regular size class
Where as all iPhones other than iphone 6S and iphone 6s + will fall to
Copact Width x Regular Height - Portrait mode
Compact Width X Compact Height - Landscape Mode
Iphone 6s and 6s + falls to
Copact Width x Regular Height - Portrait mode
Regular Width X Compact Height - Landscape Mode
Now that you are equipted with the information of all size classes lets nail this issue down. When you open the story board at the center of the screen there is option to decide the size class :)
So go ahead open up your story board when you see it by default will be in wAny wAny mode What it means is whatever the components you add and add the constraint to it will be applicable to all the sizeclasses irrespectively.
Hence you see the textField added at the center of the screen appears center in all the devices may it be iPhone ot iPad.
For explaining Ill add two text fields named Firstname and LastName :)
Lets start adding textFields and constraints to them in storyboard keeping wAny wAny mode.
Now I have added two textFields one below the other covering the whole width of the screen in any any mode :) This will work fine for me in all iPhone devices :)
But I want to allign them side by side in iPad. Now we know that iPad belongs to Regular x Regular sizee class in both the orientation :)
So Simply change the size class in storyBoard
Now when you see you will see two textfields added one below the other already :)
Now select those textfields we want to align them differently isnt it :) So will have to remove the constraints already added to them :)
Now move them place next to each other add constraints properly :)
Thats it now run on iPhone and iPad :) You will textFields one below each other in iPhone and one next to other in iPad :)
iPhone Output :
iPad output :
Hope this helps :)

Autolayout in iPhone Portrait Mode

I have to design an app for all iPhone size portrait mode only. I am using storyboard and setting constraints using storyboard itself. What makes me confuse is Size Classes. Since my requirement is iPhone portrait only, I am using Size Class compact Width|regular Height. My question is can I disable the Size Classes cause working only for iPhone portrait mode. If yes, then can I design with Size Classes disabled for all iPhone size. What is the right approach?
Intuitively, prior to size classes, storyboard UI was designed by doing a separate interface for each iPhone size. Since the advent of a broad range of device sizes, size classes have been incorporated. Considering that your app may have to run on older devices, there is still a difference in size between iPhones in portrait mode. Because of this, you would likely have to make a separate interface for each orientation, which I have not tried. I believe the correct approach would be to simply design for the size class that you selected.
If you are only making your application for iPhone portrait not necessary to use the size classes. You just have to set proper contract which are in the size indicator.
It's my opinion for it.
If you are developing for iPad and iPhone size class is the best option.
Size classes deal with the problem of multiple orientations(portrait and landscape) and different devices(iPhone and iPad). You cannot differentiate between two different screen sizes for iPhone using a size class. Similarly you cannot differentiate between iPad mini(portrait) and iPad Air(portrait) on behalf of size classes.
All iPhones in portrait has the same size class behavior i.e Compact(width) | Regular(height), be it 3.5", 4.0", 4.7" or 5.5". Similarly all iPhones in landscape has Regular(width) | Compact(height) size class. Size classes aren't the solution to the problem you are facing.
In order to handle multiple screen sizes for iPhone in portrait, the best bet would be to make use of autolayouts. Pin your views with the boundaries so that they will get stretched or contracted on different screens. Similarly bind your labels with the boundaries of their superview so that they will grow too. Also you can make use of aspect-ratio constraint that will allow to grow your view and images relative to the aspect-ratio of the element rather than increasing them horizontally to end up with an elongated look.
If you are new to autolayouts I will highly recommend watching the following sessions from WWDC2012:
Introduction to Auto Layouts
Auto Layouts by Example
Best Practices for Mastering Auto Layouts

Resources