If business reasons require you to continue supporting iOS 6, this means you may need to work with both iOS 6 and 7 for quite a while. Developers always hate this, as it may increase the code base cyclomatic complexity (e.g. if iOS 6 do this, else if iOS 7 do that…) . I love it, since my wife, mum, dad and manager are still using iOS 6.
Layout issue on iOS 7
Here is a very simple app running on iOS 6.
After switch the simulator to iOS 7, the label is missing
Why? Let’s reveal it.
The label is actually behind the NavigationBar. In iOS 7, apple introduced a new property called
[UIViewController setEdgesForExtendedLayout:] and the default value is
UIRectEdgeAll. When your container is navigation controller, the default layout will start from the top of navigation bar. This is why all of the UI elements had been shift up 44pt.
A quick way to fix this issue is add the following snippet to method
Now, it’s been fixed.
iOS 6 runtime exception
Let’s run the app on iOS 6 then, we found the following runtime exception.
All iOS 7 only API invokes need to be wrapped with proper guarder.
1 2 3 4
Xcode 4 compile error
Some machines might still running with a Xcode 4.6. When they pull the latest code, they will fail to compile then.
To avoid the compile stage error, we need to create the following macro.
1 2 3
Then wrap the iOS 7 code path if needed.
1 2 3
UILabel background inconsistency
As a UILabel, iOS 7 default background color is clearColor (which make sense most of the time), while the iOS 6 default value is white. So we’d better to explicit set the label background color.
Hide status bar while in full screen
In iOS 6, when we call
presentViewController, the default modal screen will be full screen. (
In order to achieve a consistent experience on iOS 7, we add the following code to modal controller.
1 2 3 4
Coming to iOS 7, the keyboard skin becomes lighter, so we need different barStyle for various iOS version.
1 2 3 4 5 6 7 8
More than that…
It is definitely more than that. The above tips are just some of the most common issues I have seen when working on iOS 6 & 7 codebases.