How to determine screen size in iOS

The UIDevice class can help us do that like so:

    [super viewDidLoad];
	
    // lets detect the height of our screen here
    int height = [UIScreen mainScreen].bounds.size.height;
    int width = [UIScreen mainScreen].bounds.size.width;
    
    // share the news
    NSString *message = [[NSString alloc]initWithFormat:@"This screen is \n\n%i pixels high and\n%i pixels wide", height, width];
    NSLog(@"%@", message);

This will work fine in your View Controllers and App Delegate files.

I’ve got a full working demo project on GitHub: https://github.com/versluis/ScreenSize

Further Reading:





Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.