Enabling Auto Layout in iOS 6 While Remaining Backwards Compatible With iOS 5

Enabling auto layout in iOS 6 while remaining backwards compatible with iOS 5

Autolayout can be enabled or disabled on each .storyboard or .xib file. Just select the particular file and modify the "Use Autolayout" property using the File inspector in Xcode:

autolayout property in the File inspector

Using autolayout enabled interface files with the deployment target set to an iOS version prior to 6.0 results in compilation errors, e.g.:

Error in MainStoryboard.storyboard:3: Auto Layout on iOS Versions prior to 6.0

One of your options to use autolayout in a project and still preserve compatibility with iOS4-5 is to create two targets: one for deployment target iOS 6.0 and one for an earlier iOS version, e.g.:

Sample Image

You can create two versions for each of your storyboard and XIB files as well and use the autolayout enabled with the 6.0 target and the other with the legacy target, e.g.:

Sample Image

You then add MainStoryBoardAutoSize to the iOS6 target's Build phases and the other file to the iOS4 target. You can learn more about using multiple targets here.

EDIT: As marchinram's answer points out, if you load you storyboard files from code and do not use the "Main Storyboard" setting in Xcode to set the initial storyboard, you can use a single target.

For me, the cost of the added complexity of maintaining multiple targets and interface files seems to outweigh the benefits of using autolayout. Except for a few special cases, you are probably much better to use plain old auto sizing (or layoutSubViews from code) exclusively if iOS4-5 compatibility is required.

Auto layout backwards compatibility in iOS

Autolayout was introduced at WWDC 2012 and is supported starting on iOS 6. It'll definitely not work with iOS 4.3.

I strongly recommend you to think about if you really need to support iOS 4.3 these days. We're probably very close to have iOS 7 now and you'll be years behind (technologically speaking) supporting iOS 4.3. I understand apps that are currently supporting iOS 4.3, but I don't think it's a good idea do start developing an app now with iOS 4.3 support in mind.

Update storyboard to iOS 6 with backwards compatibility

You can use springs and struts to support both form factors without requiring iOS 6.0.

Springs and struts are easy to configure in the size inspector in Interface Builder. Just select any view and use the highlighted area of the inspector in the image shown below to configure how each view should resize with its parent.

Picture highlighting springs and struts area of Interface Builder Size inspector

Turning on a strut (the outer edge objects) indicates that the distance between that edge of the subview and the same edge of the parent should stay fixed. Turning on a spring (the inner arrow) indicates that the control should grow and shrink with the parent. In the picture above, the selected view is configured to stay pinned to the bottom, left, and right edges of its superview, and to grow with the width. The example area shows an animation of how the view would move and size with the parent.

The springs and struts area of the inspector is not available in documents that use auto layout.

Make an App Complible with iO5 5 & iOS 6 Using constraints

You can create a single app that supports anywhere from iOS 4.3 on up and it will work on all devices that supports iOS 4.3 or later (or 5.0 and later if you choose).

However, NSLayoutContraint is only in iOS 6.0 and later. You will need to use other mechanisms for the app to support iOS 5.x.

Are the new object literals backwards compatible with iOS 5?

If you're using Xcode 4.5 to build your sources, then yes, they're compatible with iOS 5 as long as you use the latest LLVM compiler and you build against iOS SDK 6.0.

Xcode Create a working app for iOS 5.1 with xcode 4.6

Sounds like you might be trying to use an API that is specific to iOS6 (UICollectionView or something similar).

You need to plug the device in and run it and see what the console indicates is the problem.



Related Topics



Leave a reply



Submit