Alex Rivera | Logout

IPhone/IPad: How to get screen width programmatically?

Asked 2010-09-07T00:54:07.923
86

Hi I'm wondering if there's a way to get the width programmatically.

I'm looking for something general enough to accomodate iphone 3gs, iphone 4, ipad. Also, the width should change based on if the device is portrait or landscape (for ipad).

Anybody know how to do this?? I've been looking for a while... thanks!

Edit
Report

1 Answer

12
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat width = CGRectGetWidth(screen);
//Bonus height.
CGFloat height = CGRectGetHeight(screen);
answered 2010-09-07T01:01:16.300

Your Answer