Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 12    Views: 92

Angry Ninja
Aspiring developer
Profile
Posts: 1045
Reg: Aug 25, 2013
Maine
17,150
03/01/14 05:56 PM (10 years ago)

Super Easy iPhone 4 or iPhone 5 Screen Size Code

I needed a particular table to draw one size for the 3.5" iphone screens, and another size for the newer 4" iphone 5 screens. Found a super simple way, and thought I would share it. I just enter it in the plugins .m file where I needed to differentiate between the two. ------------------------------------------------------------------ Towards the top of the .m file, after the framework imports, add this line: ------------------------------------------------------------------ #define IsIphone5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON ) ------------------------------------------------------------------ Then, in the same .m file, wherever you need to run different code based on the iphone size, add this: ------------------------------------------------------------------ if(IsIphone5) { //your stuff } else { //your stuff } May be basic stuff for some of the more advanced coders, but I never had to use it before until now, and was surprised at how easy it was with just a couple lines of code.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/01/14 06:19 PM (10 years ago)
Pretty spiffy. A bit less complicated than what I'm using now. Thanks! :) Cheers! -- Smug
 
Angry Ninja
Aspiring developer
Profile
Posts: 1045
Reg: Aug 25, 2013
Maine
17,150
like
03/01/14 06:20 PM (10 years ago)
Yeah, I seen some more complex codes out there, but was impressed at how short this one was
 
NCbuzz
Code is Art
Profile
Posts: 575
Reg: Sep 11, 2013
Lillington, NC
11,100
like
03/01/14 06:40 PM (10 years ago)
Thanks! I had just sprinkled a couple of checks in some screens today. This is much cleaner.
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
03/01/14 07:12 PM (10 years ago)
I see in the Video Playlist plugin, a similar directive: #define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES) --------------------------------------- Then in Jake's JC_Launch_Screen, I see this: if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) { CGSize result = [[UIScreen mainScreen] bounds].size; if (result == 480) { // iPhone 3 & 4 stuff for a 3.5" screen } if (result == 568 { // iPhone 5 stuff for a 4" screen } } // ENDIF for all iPhone and iPod touch if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) { // iPad stuff } // ENDIF for all iPad
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
03/01/14 07:21 PM (10 years ago)
Another way to check if you are running on an iPad if ( [(NSString*) [UIDevice currentDevice].model isEqualToString:@"iPad"] ) { // Do iPad things } ---------------------- Also, Buzztouch has a built-in method by which to check if running on an iPad: (it queries the UI_USER_INTERFACE_IDIOM method to set an appDelegate property) if ( [self.rootDevice isIPad] ) { // Do iPad things } else { // Do iPhone things }
 
Angry Ninja
Aspiring developer
Profile
Posts: 1045
Reg: Aug 25, 2013
Maine
17,150
like
03/01/14 07:42 PM (10 years ago)
Cool stuff :)
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
03/01/14 07:43 PM (10 years ago)
Wait until the AppleTV emerges as an app platform, that will turn our world into a tizzy! :-)
 
Angry Ninja
Aspiring developer
Profile
Posts: 1045
Reg: Aug 25, 2013
Maine
17,150
like
03/01/14 07:50 PM (10 years ago)
It already is if yours is jailbroken ;) I used to use a jailbroken apple TV, but now run XMBC on other devices for my entire home network. The appletv hardware just couldn't handle my XBMC setup... not enough processing power.
 
NCbuzz
Code is Art
Profile
Posts: 575
Reg: Sep 11, 2013
Lillington, NC
11,100
like
03/01/14 08:34 PM (10 years ago)
Would be nice if BT made the determination and added to appDelegate so we could access in any screen. Somethin like: [self.rootDevice isiPhone5] ;) Can't always count on [self.rootDevice deviceHeight] unless the iPhone app does not allow rotation.
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
03/01/14 10:14 PM (10 years ago)
Hey Mustang .. I understand your desire to know if the device height based on it's rotation. Did you figure out a way, or need me to jimmy up a code block? :-) I am knee-deep on making the Control Panel for that new plugin ... don't get me distracted, guys!
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
03/02/14 12:51 PM (10 years ago)
Nice Ninja!! Thanks a lot. Sweet and simple
 
NCbuzz
Code is Art
Profile
Posts: 575
Reg: Sep 11, 2013
Lillington, NC
11,100
like
03/02/14 05:40 PM (10 years ago)
Niraj Stay on that Control Panel for your new plugin! Besides my app will be Portrait only ;)
 

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.