How to get screen size using code on iOS?

haisergeant picture haisergeant · Sep 3, 2010 · Viewed 77.8k times · Source

How to get the iPhone screen size to give calculation?

Answer

Tim picture Tim · Sep 3, 2010

You can use the bounds property on an instance of UIScreen:

CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;  
CGFloat screenWidth = screenSize.width;
CGFloat screenHeight = screenSize.height;

Most people will want the main screen; if you have a device attached to a TV, you may instead want to iterate over UIScreens and get the bounds for each.

More info at the UIScreen class docs.