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

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.

Your question deserves a longer answer than StackOverflow can provide, but there are a few pointers I can give you.
For each of your xibs, enable Size Classes and Autolayout.
Set each xib root view's size class to width Any and height Any, which I believe are the defaults.
Design your interface in a way that looks decent on this theoretical Any x Any device.
I highly recommend using a UIScrollView at the top level of any view controller's view hierarchy.
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.
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.
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.

Related

Auto-layout not regular across different screen size

I am new to iOS platform but still been able to build my first app in the last 3 weeks. Coming from android, I was able to leverage of some of the knowledge I had to adapt quickly to swift and iOS but I struggle with auto-layout in the storyboard. I have not been able to get a flow that works.
I am currently using Xcode 11 and have tried to UIScrollView but to no uniformity. Whatever I arrange correctly on iPhone 11 deforms on iPhone 8 or lower.
I have watched different tutorials on youtube, lynda.com and pluralsight but to no avail.
What is the best possible way to use auto-layout across different screens like we have in android with constraint layout/relative layout?
I recommend using anchor constrains programmatically. Setting border relative to different items will provide autolayout in all devices. If you post a screenshot of your needs , it might be easier to provide accurate answer. Also keep in mind that superview borders in iphone 8 and lower version differ from borders in higher version according to the top notches. You need to set your views relative to safe area of the superview.

Resize UI to fit iphone 6/6+ without using auto-layout

I am building an ios app and I have been developing it on iphone 5 size class. I have done it this way because I have not yet learned how to use auto-layout. I was wondering if there was a way(other than auto-layout) that I can use, on this app so that the view fits perfectly in iphone 5/5c/5s and 6/6+
Without auto-layout the available solutions will be pretty rough. Because your lengths are all hard values-- you will have to manually manipulate them to achieve the size you want in an iPhone 6. It would definitely still be slightly more time consuming to apply auto-layout constraints onto all of your views-- but you would be safe from having to do this again in the future. Hopefully you don't have too many views :)

iOS 8 auto layout? Do I need it?

Is there a way to have an app work on all tall iPhone devices (portrait mode) without using Auto Layout?
Can I just design for say iPhone 5 and have iPhone 6 and iPhone 6 plus stretch to fill.
Auto layout seems overkill when I don't need to design for landscape or iPad.
Any ideas?
Auto layout seems overkill when I don't need to design for landscape
or iPad.
That's definitely not true. You could argue it was true before the launch of the iPhone 6, but even with only iPhones 4 and 5 it helps to account for different situations.
Can I just design for say iPhone 5 and have iPhone 6 and iPhone 6 plus
stretch to fill.
Stretch to fill is something that you can easily achieve with AutoLayout.
I know it seems a bit tough at first, but it's actually based on really simple mechanisms and behaves very logically. It's definetely worth giving it a try, you'll get much more out of it than you might expect right not.
Although Auto layout is optional, but to me it is a recommended feature.
Once your design become complex, you would have to write a lot of code to support different screen sizes. This can be avoided by using auto-layouts.
Yes you can in Show the size inspector-> Autoresizing. But you have to do it for each subview for each .xib file or in storyboard

UITextfield Custom Position moved up because of different iPhone sizes

I have several custom UITextfields in my app. I started this app on Xcode 5 and ran on iphone 5 simulator. After Xcode updated to Xcode 6, I ran the app on iPhone 6 simulator. Now all the textfield positions moved up because of large screen size. I just wanted to know is there anything I could do so that the positions of textfields automatically get adjusted depending upon the iPhone models.
You need to rebuild your interface to handle the different screen sizes. In particular, you need to work with the AutoLayout feature to help determine how you want everything to scale/move/position based on multiple screen sizes. This can be done via the Storyboard (easier but sometimes frustrating) or in code (harder at first but more control later). I usually use Storyboards and it's worked great on several projects.
Do you want it centered and respecting your original layout and margins? a certain distance from the top or sides? everything scaled up appropriately? All these things can be done with AutoLayouts.
Check out the great tutorial here for more information:
http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

Supporting multiple iPhone resolutions with a single storyboard

We all are going to update our apps to iphone 6 and iphone 6 plus. That means we need to support 4 sizes.
1.) 3.5
2.) 4
3.) 4.7
4.) 5.5
Can we support all these screen sizes with single xib or storyboard ? also please share your views on how we can update our existing apps for iphone 6 and iphone 6 plus.
Yes. See Apple's iOS8 documentation specifically, size classes:
iOS 8 makes dealing with screen size and orientation much more versatile. It is easier than ever to create a single interface for your app that works well on both iPad and iPhone, adjusting to orientation changes and different screen sizes as needed. Design apps with a common interface and then customize them for different size classes. Adapt your user interface to the strengths of each form factor. You no longer need to create a specific iPad storyboard; instead target the appropriate size classes and tune your interface for the best experience.
There are two types of size classes in iOS 8: regular and compact. A regular size class denotes either a large amount of screen space, such as on an iPad, or a commonly adopted paradigm that provides the illusion of a large amount of screen space, such as scrolling on an iPhone. Every device is defined by a size class, both vertically and horizontally.
There is also a very good tutorial video on the WWDC site.
In order to stop your iPhone 6/6+ app being scaled, add a launch image of the correct size or better, use a launch storyboard.
From there you should use AutoLayout and avoid hard coding to screen sizes. In the long run it'll be a lot less effort and less error prone.
In existing projects you can use autoresizing or auto layout of xib files.. that support all 4 devices.
I have implement my projects using autoresizing to support all devices.

Resources