Ready to Level-Up?

This just in! If your rusty iOS skills could use some refining, or if you're just starting out and you want to level-up fast, consider signing up for our upcoming iOS Screencasts

New from iOS Rocket Surgery Swift Video Tutorials: The rapidly evolving Apple-iOS ecosystem has just been thrown into tumult with the recent introduction of the Swift Programming Language. Are you ready to finally try iOS development? Are you needing to switch from Objective-C to Swift? Sign up today for our free video courses!
(By the dear folks at Swift Tutorial Videos, a sister company)

Wednesday, December 18, 2013

iOS Get Bounds of Screen

So, you want to know how big the screen is (bounds) on an iOS device, eh?

Unfortunately, you can't rely on the screen sizes that you know right now, as device releases tend to confound the most thorough static-coders who rely on fixed sized. Sigh, those were the days. Now, you don't have it nearly as bad as the Android folks have it, not by a long shot, so the variance of screen sizes is more of an annoyance than anything. So, since you're the kind of person who likes to dynamically calculate screen size, then I have some code for you.

Here's an example of how to get the iOS screen bounds:


  CGRect screenBoundsRect = [[UIScreen mainScreen] bounds];
  
  // Now get the width/height of the screen
  CGFloat width = screenBoundsRect.size.width;
  CGFloat height = screenBoundsRect.size.height;


You should now thank your lucky stars that you chose iOS, if only for the limited number of devices of various sizes and memory constraints. Heaven help us that we ever see days like Android has seen.

If you liked this post because you just climbed down from the mountains, have a manly beard (or are otherwise roughly-shod and wear flannel), and you appreciate the taste of cold-brewed iOS code examples, then give us a +1 and we'll show you the world. Now, go chop some trees.




About Me

Easy NSDateFormatter Tool

Save yourself some time in formatting your NSDates to NSStrings, and use the Blind NSDate app, which you can download from iTunes. There's also a website where you can format your NSDates: http://www.blindnsdate.com

Popular Posts

Designed By Seo Blogger Templates