vinay vinay - 1 year ago 89
iOS Question

What is the use of UIScreen property in UIWindow?

I was looking at the

class reference and there I found the
property which defaults to
[UIScreen mainScreen]

@property(nonatomic,retain) UIScreen *screen NS_AVAILABLE_IOS(3_2);
// default is [UIScreen mainScreen]. changing the screen may be an expensive operation and should not be done in performance-sensitive code

We initiailise the
object with the

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]

I am wondering why do we need the
property in

Answer Source

UIScreen refers to the device frame.

You can get the device size for finding the Devices iPhone 4,iPhone 5, iPhone 6, iPhone 6+ & iPad

[[UIScreen mainScreen] bounds] //gives u the size of the device.

You can differentiate the devices as per above sizes.

[[UIScreen mainScreen] bounds].size.width //gives the width of device [[UIScreen mainScreen] bounds].size.height) //gives the height of device.

Or you can use in this way

CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];

Hope it helps you...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download