Support iOS7 and lower!

The new iOS 7 came out and it's time for updating the apps, the new look & feel feels clean, but not very helpful and usable for the moment. A lot have been complaining about the new look & feel, but it's a matter of time until they will get it.

So, back to our subject, backwards compatibility specially for the UI elements of your app. Ok, let's be truthful, I won't show you backwards compatibility for all versions of iOS, but I'll show you how to support iOS 7 and iOS 6! If you haven't found it out, the new looks of the iOS makes us make some changes in positioning the whole UI of the app. The top bar of the device is not the starting point of your app (at least if you show it). Now everything starts literally from the beginning of the screen. So, what you have to do is, move your UI a little bit lower. To be more specific you have to move them 10 points below.

Here's the code for doing it.

1: #define IS_IOS7 [[UIDevice currentDevice].systemVersion hasPrefix:@"7"]
2:  if (IS_IO7) { 
3:      CGRect tmpFrame = self.yourView.frame;  
4:      tmpFrame.origin.y += 10; // move further from the status bar  
5:      tmpFrame.size.height -= 10; // to fit the screen  
6:      self.yourView.frame = tmpFrame;  
7:  }  

That's one quick way, but you can achieve the same with this.

1:  - (CGFloat)topOfViewOffset  
2:  {  
3:    CGFloat top = 0;  
4:    if ([self respondsToSelector:@selector(topLayoutGuide)])  
5:    {  
6:      top = self.topLayoutGuide.length;  
7:    }  
8:    return top;  
9:  }  
1:  - (CGFloat)topOfViewOffset  
2:  {  
3:    CGFloat top = 0;  
4:    if (IS_IO7)  
5:      top = self.topLayoutGuide.length;  
6:      
7:    return top;  
Found: here
Apparently with the second solution you don't have to use the macro all the time. Right now I have a few improved variations of this in mind, but I'll let you imagine.

Sorry for the indentation, I have to fix this page to support the <code> tag! :)

Code formatted using: http://codeformatter.blogspot.se/

3 comments

  1. Glad you found my post useful. Tell me, though - why do you use the __IPHONE_7_0 macro instead of respondsToSelector?

    ReplyDelete
    Replies
    1. I think that with the pre-processor you can make your code lighter, since this part will be omitted. Though, I'm not 100% sure about that.

      Delete
    2. It felt more natural to add that, actually a better way is to do something similar by checking the minimum iphone version. I am not sure, but I have the feeling that macros don't change as often as methods. That might be nonsense at the same time, but that's my feeling.

      Delete

 

Most Reading