iosiphonecocoa-touchuiscreen

How to get screen size using code on iOS?


How to get the iPhone screen size to give calculation?


Solution

  • 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.