Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 1    Views: 73

SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
03/21/16 02:51 PM (8 years ago)

quick and easy device size detection (iOS)

Better than the old 'isIPad' test... if you need to get really particular, you can 'split' between landscape and portrait by replacing '&&' with '} else if' CGRect screenBounds = [[UIScreen mainScreen] bounds]; int screenHeight = screenBounds.size.height; int screenWidth = screenBounds.size.width; if (((screenHeight == 480)&&(screenWidth == 320))||((screenHeight == 320) && (screenWidth == 480))) { // iPhone 4 [BT_debugger showIt:self message:[NSString stringWithFormat:@"iDevice: %@", @"iPhone 4"]]; } else if (((screenHeight == 568)&&(screenWidth == 320))||((screenHeight == 320) && (screenWidth == 568))) { // iPhone 5 [BT_debugger showIt:self message:[NSString stringWithFormat:@"iDevice: %@", @"iPhone 5"]]; } else if (((screenHeight == 667)&&(screenWidth == 335))||((screenHeight == 335) && (screenWidth == 667))) { // iPhone 6 [BT_debugger showIt:self message:[NSString stringWithFormat:@"iDevice: %@", @"iPhone 6"]]; } else if (((screenHeight == 736)&&(screenWidth == 414))||((screenHeight == 414) && (screenWidth == 736))) { // iPhone 6+ [BT_debugger showIt:self message:[NSString stringWithFormat:@"iDevice: %@", @"iPhone 6+"]]; } else if (((screenHeight == 1024)&&(screenWidth == 768))||((screenHeight == 768) && (screenWidth == 1024))) { // iPad [BT_debugger showIt:self message:[NSString stringWithFormat:@"iDevice: %@", @"iPad Family"]]; } else if (((screenHeight == 1366)&&(screenWidth == 1024))||((screenHeight == 1024) && (screenWidth == 1366))) { // iPad Pro [BT_debugger showIt:self message:[NSString stringWithFormat:@"iDevice: %@", @"iPad Pro"]]; } Hope this helps someone. At the very least, it's annoying to type and tedious to keep it straight ;) Cheers! -- Smug
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
03/25/16 07:02 AM (8 years ago)
and we used to gripe about Android device fragmentation..... check out UITraitCollection http://makeapppie.com/tag/uitraitcollection/ http://blog.flatironschool.com/working-with-size-classes-in-code-with/ I came across it trying to deal with rotation. This would be a great method for BT to adopt and use in the BT core to deal with all these device sizes and more importantly - rotation.
 

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.