Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 2    Views: 178

tb
buzztouch Evangelist
Profile
Posts: 2050
Reg: Nov 03, 2011
Oxford
32,300
05/29/16 05:29 AM (8 years ago)

Determining iOS screen sizes

Hi all, I've been spending the last few days updating an older app of mine for a client, and of course these days iOS have about a billion different screen sizes which just makes my life a billion times more complicated. First of all, a little back story. It's odd how when I first found myself making apps, it was relatively straight-forward, with just two screen sizes, the iPhone 3.5" screen and the iPad 9.7" screen. I used to smirk at fellow Android users who had difficulty with their sizes, but things have changed in the Apple eco-system. Now, the iPhone has four sizes to cater for (3.5", 4", 4.7", 5.5") and the iPad has three sizes (7.9", 9.7" and 12.9"). That's a whopping seven sizes to cater for in the iOS range. I understand why Apple have gone down this route. As a consumer of all seven sizes, I love the size that my iPhone 6 Plus and iPad Pro offers, and I get why no one size fits all. It's a clear shift from the old Steve Job's design-led leadership to the new sales-led (design-less) leadership which is Apple's current iteration. Anyway, the upshot of my lovely story is that app development in the iOS ecosystem has got a million times harder in the last three or four years. Apple has tried catering for this by introducing auto-layouts and other tools such wonderful Xcode tools. Don't get me wrong, Auto-layouts is a developer's godsend, however especially when using older Buzztouch plugins, sometimes you just need to dig around in the code a bit. Also, if you thought dealing with various screen sizes was an issue, you also have to deal with iOS's weird pixel points stuff and downscaling for the @3x stuff and upscaling for @2x and so on. Here is actually a really good link to explaining iOS screen sizes: http://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions Over the last few days, I've been starting to do the tedious process of writing different code for each screen size. It's not recommended but sometimes it is the quickest and easiest way to solve a problem in older code. I've found a nifty little section of code that is just great and I've been using it all the time and splits the code into various screen sizes. I use this code basically everywhere in the app, including in BT_appdelegate and BT_utilities files as well as in the plugins themselves. I am finding it's best use is in determining variable values, such as image width and height, or frame height, or so on. These selection of if statements have been incredibly useful, so I thought it'd be worth sharing with all you folks too. if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ){ CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; if( screenHeight < screenWidth ){ screenHeight = screenWidth; } if( screenHeight > 480 && screenHeight < 667 ){ NSLog(@"iPhone 5/5s"); } else if ( screenHeight > 480 && screenHeight < 736 ){ NSLog(@"iPhone 6"); } else if ( screenHeight > 480 ){ NSLog(@"iPhone 6 Plus"); } else { NSLog(@"iPhone 4/4s"); } } I hope it helps, Thomas
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/31/16 03:32 AM (8 years ago)
Thanks Thomas. Nice to see you around again. Cheers! -- Smug
 
Jake Chasan
Veteran developer
Profile
Posts: 1685
Reg: May 13, 2011
location unknow...
29,650
like
05/31/16 04:50 PM (8 years ago)
Hi Thomas, It is great to hear from you again. I believe that I have an even easier way to accomplish this, which will reduce the amount of computations by nearly half: if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){ CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; if(screenHeight < screenWidth){ screenHeight = screenWidth; } if(screenHeight <= 480){ NSLog(@"iPhone 4/4s"); } else if(screenHeight <= 568){ NSLog(@"iPhone 5/5s"); } else if(screenHeight <= 667){ NSLog(@"iPhone 6/6s"); } else if(screenHeight <= 736){ NSLog(@"iPhone 6+/6s+"); } Jake
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.