Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best way to make a viewcontroller for different screens

I would like to know which is the best way to make a view controller for iOS 9 swift 2 xcode 7, for different iPhone screens?

I have tried to make it with constrains but from iphone 4s to iphone 6s screens we can see wide gaps between the icons and text fields etc.

What i'm thinking is to make different view controllers for each screen (5.5inches, 4.7inches, 3.5inches) and to make my app check with which screen the user is opening the app and load the unigue view controller for this screen.

Or maybe there is a better way but im new to swift 2.0 so i'm asking for your help!

Thanks a lot for your time.

like image 968
Konstantinos Natsios Avatar asked Dec 10 '15 11:12

Konstantinos Natsios


People also ask

How do you create a new ViewController in a storyboard?

Click on background of Main. storyboard . Search and select ViewController from object library at the utility window. Drag and drop it in background to create a new ViewController .


4 Answers

You can make a views for multiple screens using autolyout and size classes. You have proportional constraints that fit on all screens.

Proportional constraints means you can set for example view1 is 50% of screen. These constraints fit on all screens.

Avoid excessive use of size classes (applying constraint in different size class). Try to go with proportional constraints in hAny wAny layout.

Only go for different size class if design on ipad is different then iphone. Or if you need different font sizes on different devices.

https://developer.apple.com/library/ios/recipes/xcode_help-IB_auto_layout/chapters/EditingConstraintAttributesintheAttributesInspector.html

like image 185
Irfan Avatar answered Oct 19 '22 07:10

Irfan


I think this depends upon what your requirement is and what you prefer.
I usually prefer the good old Springs and Struts.
They can be used by disabling auto layout and screen sizes.
Using Springs and Struts i only create a single Storyboard to manage all iPhone and iPad screen sizes without any coding effort.
No matter how complex the UI maybe, for me Springs and Struts are the best solution.

like image 45
S1LENT WARRIOR Avatar answered Oct 19 '22 05:10

S1LENT WARRIOR


Size classes give you a more fine grain control for different sizes and orientations. Please refer Apple's documentation

like image 1
ITGronk Avatar answered Oct 19 '22 07:10

ITGronk


As I understood your question that you want to load storyboard as size of screen of device.

I will suggest you to refer this link to load a different storyboard depending on screen size. Sorry for Objective c but hope it helps you. Load different storyboards

like image 1
Bhavin Ramani Avatar answered Oct 19 '22 06:10

Bhavin Ramani