Backward compatibility of iOS Size Classes

New iOS Size classes provide a more flexible way to build interfaces for multiple devices. I personally like the idea of having only one interface. What I like even more is the possibility to use different layouts for landscape and portrait orientations. However, most of developers have to support < 8.0 iOS versions and therefore the question about backward compatibility is very actual.

Size classes in Storyboard

To carry out my experiments, I created a sample app that just shows a label with the corresponding size class or classes. Note that following results apply only to Storyboard, nibs cases will be investigated later.

I first checked that in iOS 8 all size classes work as expected. Then I switched to iOS 7.

On iPad Air with iOS 7.1 everything worked nicely and iPad showed that it is belonging to Any Width+Regular Height, Regular Width+Regular Height and Regular Width+Any Height classes.

There was also no problems with iPhones in portrait mode in iOS 7.

However, iPhone 5S with iOS 7.1 showed portrait labels in landscape.

Therefore, backward compatibility of size classes does not apply to compact height layouts. Everything else should work and if it doesn’t, there’s probably some mistake.

Size classes in Xib files

The situation with Xibs is a bit more complicated. According to Apple document, the iPhone nib is based on a display with a compact width and regular height. The iPad nib is generated based on a regular width and regular height. 

For Xib testing I used only two size classes – Regular Width+Regular Height and Compact Width+Regular Height. Those classes should be enough to differentiate between iPads and iPhones and have to be backward compatible with iOS 7 according to Apple.

The sample app will show a red square and the size of the square will vary according to size class. For Regular Width+Regular Height it’ll be 600x600px and for Compact Width layout 300x300px.

Of course, everything works as expected on iOS 8. However, on iOS 7 only iPhone layouts do work correctly and iPad use incorrect size of 300px.

iOS 8.0

Screen Shot 2014-10-22 at 22.22.06

iOS 7.1

Screen Shot 2014-10-22 at 22.22.53

Looking into the compiled app reveals that Xcode actually generates two nibs for both iPhone and iPad, however it actually does not work.

Screen Shot 2014-10-22 at 22.20.15

Hopefully I’m just doing something wrong, but for me it seems like a nasty Xcode bug. If you find a way to make size classes in Xibs backward compatible, let me know 🙂

For now, I think the conclusion is that size classes with Xibs are not backward compatible.

If you need backward compatibility and wish to use size classes, then maybe storyboards is the right way to go. Choosing xibs and turning size classes off is another option.

One Response
  1. ios development courses

Leave a Reply

Your email address will not be published. Required fields are marked *