Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to support one xib for all iPhone devices upto iPhone 6 Plus?

I started one new iOS apllication. And that application requirement is app should support from iPhone 4 to iPhone 6 Plus. I am very much familiar with using Xib files. So far I differentiated my apps with iPhone 5 and below iPhone 5. For that I Used 2 Xib files for one is for iPhone 5 and other is iPhone 5 below according to device height I added like that. But now apple has relased iPhone 6 and iPhone 6 Plus with iOS 8 along with XCode 6. For these 4 types devices,

1) iPhone 4 2) iPhone 5 3) iPhone 6 and 4) iPhone 6 Plus do I need to add 4 Xibs or any other solution.

To learn Storyboards, now I don't have that much time because my app has already release date confirmed from Client. But I will learn about sotryboard in future definately.

I have tried with Autolayout concept, but its not worked for me. and I dont have full awarness on Autolayout concept also. Yesterday I started my new project with XCode 6, So I taken iPhone 6 view and tried to use autoresizing and autolayout but not worked for me and views are overlapping. I know for different devices creating different xibs is not good practice. For creating each device with each xib would take huge time. I am really bothering about this how to handle different devices from yesterday onwards. Please somebody help me to came out from this issue. Really highly thankful to you. If anything mistakes in my content please forgive me.

like image 473
Anilkumar iOS - ReactNative Avatar asked Sep 19 '14 05:09

Anilkumar iOS - ReactNative


1 Answers

Your question deserves a longer answer than StackOverflow can provide, but there are a few pointers I can give you.

  1. For each of your xibs, enable Size Classes and Autolayout.
  2. Set each xib root view's size class to width Any and height Any, which I believe are the defaults.
  3. Design your interface in a way that looks decent on this theoretical Any x Any device.
  4. I highly recommend using a UIScrollView at the top level of any view controller's view hierarchy.
  5. Use constraints to anchor the controls. I find it easiest to start with the control in the top left corner, anchor it to the containing view's top and left sides, and then work your way down and across until all of your controls are constrained on all 4 sides, or on one vertical and one horizontal size, along with explicit height and width. Be generous with the greater-than and less-than relationships in your constraints.
  6. To customize for each device layout, switch the size class to the desired combination. Note that any constraints you add, change, or remove, as well as any controls that you add or remove, will be changed only for the current class size. Do this for each different size class that you're going to support. See Apple's reference for which size classes are used for each device.
  7. Test your layouts using the Resizable Device simulators.

This is hard work, but it sure beats having to maintain a different xib for each device size.

like image 60
NRitH Avatar answered Sep 22 '22 10:09

NRitH