Wednesday, November 27, 2013

Getting the screen size in iOS

To get the screen size in iOS available for the app,

        CGFloat fScreenHeight = 0.0;

        if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
            fScreenHeight = [UIScreen mainScreen].applicationFrame.size.width;
        }
        else{
            fScreenHeight = [UIScreen mainScreen].applicationFrame.size.height;
        }

        NSLog(@"Screen Height = %02f", fScreenHeight);

We can get the screen width by doing just vice versa. 

This will give us the screen size available for the app, i.e. after reducing the height of the status bar. For iPhone in portrait mode this will give the height as 460, which is 480-20.

No comments:

Post a Comment