The UIDevice class can help us do that like so:
1 2 3 4 5 6 7 8 9 |
[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: