How to determine screen size in iOS

- by

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:



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.