UIScreen学习记录




UIScreen object contains the bounding rectangle of the device’s entire screen. When setting up your application’s user interface, you should use the properties of this object to get the recommended frame rectangles for your application’s window.

UIScreen对象包含了整个屏幕的边界矩形。当构造应用的用户界面接口时,你应该使用该对象的属性来获得推荐的矩形大小,用以构造你的程序窗口。

以下列出的属性和操作是我用过的。



 



+ mainScreen        Returns the screen object representing the device’s screen.

bounds  property    Contains the bounding rectangle of the screen, measured in points. (read-only)
applicationFrame  property  The frame rectangle for the app window. (read-only)
scale  property   The natural scale factor associated with the screen. (read-only)


CGRect bound = [[UIScreen mainScreen] bounds];  // 返回的是带有状态栏的Rect
CGRect frame = [[UIScreen mainScreen] applicationFrame];  // 返回的是不带有状态栏的Rect
float scale = [[UIScreen mainScreen] scale]; // 得到设备的自然分辨率

 备注:状态栏高度为20


 


UIScreen学习记录_状态栏


 



根据不同设备获取到的参数数据:



 1. iphone 6s plus


//设备类型
    NSString* deviceType = @"iphone 6s plus";
    //显示分辨率
    UIScreen* mainScreen = [UIScreen mainScreen];
    //bounds:只读属性,返回整个屏幕的rect (包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.bounds:%@",deviceType,NSStringFromCGRect(mainScreen.bounds));
    //applicationFrame:只读属性,返回状态栏之下的屏幕的rect (不包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.applicationFrame:%@",deviceType,NSStringFromCGRect(mainScreen.applicationFrame));
    //设备的分辨率:只读属性
    NSLog(@"[%@] mainScreen.scale:%f",deviceType,mainScreen.scale);
    //屏幕亮度:取值范围为0-1.0
    NSLog(@"[%@] mainScreen.brightness:%f",deviceType,mainScreen.brightness);


[iphone 6s plus] mainScreen.bounds:{{0, 0}, {414, 736}}
 [iphone 6s plus] mainScreen.applicationFrame:{{0, 20}, {414, 716}}
 [iphone 6s plus] mainScreen.scale:3.000000
 [iphone 6s plus] mainScreen.brightness:0.500000


 


 2. iphone 6s

//设备类型
    NSString* deviceType = @"iphone 6s";
    //显示分辨率
    UIScreen* mainScreen = [UIScreen mainScreen];
    //bounds:只读属性,返回整个屏幕的rect (包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.bounds:%@",deviceType,NSStringFromCGRect(mainScreen.bounds));
    //applicationFrame:只读属性,返回状态栏之下的屏幕的rect (不包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.applicationFrame:%@",deviceType,NSStringFromCGRect(mainScreen.applicationFrame));
    //设备的分辨率:只读属性
    NSLog(@"[%@] mainScreen.scale:%f",deviceType,mainScreen.scale);
    //屏幕亮度:取值范围为0-1.0
    NSLog(@"[%@] mainScreen.brightness:%f",deviceType,mainScreen.brightness);


 [iphone 6s] mainScreen.bounds:{{0, 0}, {375, 667}}
 [iphone 6s] mainScreen.applicationFrame:{{0, 20}, {375, 647}}
 [iphone 6s] mainScreen.scale:2.000000
 [iphone 6s] mainScreen.brightness:0.500000


 


 3. iphone 6 plus


//设备类型
    NSString* deviceType = @"iphone 6 plus";
    //显示分辨率
    UIScreen* mainScreen = [UIScreen mainScreen];
    //bounds:只读属性,返回整个屏幕的rect (包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.bounds:%@",deviceType,NSStringFromCGRect(mainScreen.bounds));
    //applicationFrame:只读属性,返回状态栏之下的屏幕的rect (不包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.applicationFrame:%@",deviceType,NSStringFromCGRect(mainScreen.applicationFrame));
    //设备的分辨率:只读属性
    NSLog(@"[%@] mainScreen.scale:%f",deviceType,mainScreen.scale);
    //屏幕亮度:取值范围为0-1.0
    NSLog(@"[%@] mainScreen.brightness:%f",deviceType,mainScreen.brightness);


 [iphone 6 plus] mainScreen.bounds:{{0, 0}, {414, 736}}
 [iphone 6 plus] mainScreen.applicationFrame:{{0, 20}, {414, 716}}
 [iphone 6 plus] mainScreen.scale:3.000000
 [iphone 6 plus] mainScreen.brightness:0.500000


4. iphone 6


//设备类型
    NSString* deviceType = @"iphone 6";
    //显示分辨率
    UIScreen* mainScreen = [UIScreen mainScreen];
    //bounds:只读属性,返回整个屏幕的rect (包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.bounds:%@",deviceType,NSStringFromCGRect(mainScreen.bounds));
    //applicationFrame:只读属性,返回状态栏之下的屏幕的rect (不包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.applicationFrame:%@",deviceType,NSStringFromCGRect(mainScreen.applicationFrame));
    //设备的分辨率:只读属性
    NSLog(@"[%@] mainScreen.scale:%f",deviceType,mainScreen.scale);
    //屏幕亮度:取值范围为0-1.0
    NSLog(@"[%@] mainScreen.brightness:%f",deviceType,mainScreen.brightness);


输出:


 [iphone 6] mainScreen.bounds:{{0, 0}, {375, 667}}
 [iphone 6] mainScreen.applicationFrame:{{0, 20}, {375, 647}}
 [iphone 6] mainScreen.scale:2.000000
 [iphone 6] mainScreen.brightness:0.500000


 


5. iphone 5s


//设备类型
    NSString* deviceType = @"iphone 5s";
    //显示分辨率
    UIScreen* mainScreen = [UIScreen mainScreen];
    //bounds:只读属性,返回整个屏幕的rect (包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.bounds:%@",deviceType,NSStringFromCGRect(mainScreen.bounds));
    //applicationFrame:只读属性,返回状态栏之下的屏幕的rect (不包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.applicationFrame:%@",deviceType,NSStringFromCGRect(mainScreen.applicationFrame));
    //设备的分辨率:只读属性
    NSLog(@"[%@] mainScreen.scale:%f",deviceType,mainScreen.scale);
    //屏幕亮度:取值范围为0-1.0
    NSLog(@"[%@] mainScreen.brightness:%f",deviceType,mainScreen.brightness);

  

输出:


 [iphone 5s] mainScreen.bounds:{{0, 0}, {320, 568}}
 [iphone 5s] mainScreen.applicationFrame:{{0, 20}, {320, 548}}
 [iphone 5s] mainScreen.scale:2.000000
 [iphone 5s] mainScreen.brightness:0.500000


6. iphone 5


//设备类型
    NSString* deviceType = @"iphone 5";
    //显示分辨率
    UIScreen* mainScreen = [UIScreen mainScreen];
    //bounds:只读属性,返回整个屏幕的rect (包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.bounds:%@",deviceType,NSStringFromCGRect(mainScreen.bounds));
    //applicationFrame:只读属性,返回状态栏之下的屏幕的rect (不包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.applicationFrame:%@",deviceType,NSStringFromCGRect(mainScreen.applicationFrame));
    //设备的分辨率:只读属性
    NSLog(@"[%@] mainScreen.scale:%f",deviceType,mainScreen.scale);
    //屏幕亮度:取值范围为0-1.0
    NSLog(@"[%@] mainScreen.brightness:%f",deviceType,mainScreen.brightness);


 [iphone 5] mainScreen.bounds:{{0, 0}, {320, 568}}
 [iphone 5] mainScreen.applicationFrame:{{0, 20}, {320, 548}}
 [iphone 5] mainScreen.scale:2.000000
 [iphone 5] mainScreen.brightness:0.500000


7. iphone 4s


//设备类型
    NSString* deviceType = @"iphone 4s";
    //显示分辨率
    UIScreen* mainScreen = [UIScreen mainScreen];
    //bounds:只读属性,返回整个屏幕的rect (包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.bounds:%@",deviceType,NSStringFromCGRect(mainScreen.bounds));
    //applicationFrame:只读属性,返回状态栏之下的屏幕的rect (不包含顶部的状态栏)
    NSLog(@"[%@] mainScreen.applicationFrame:%@",deviceType,NSStringFromCGRect(mainScreen.applicationFrame));
    //设备的分辨率:只读属性
    NSLog(@"[%@] mainScreen.scale:%f",deviceType,mainScreen.scale);
    //屏幕亮度:取值范围为0-1.0
    NSLog(@"[%@] mainScreen.brightness:%f",deviceType,mainScreen.brightness);


 [iphone 4s] mainScreen.bounds:{{0, 0}, {320, 480}}
 [iphone 4s] mainScreen.applicationFrame:{{0, 20}, {320, 460}}
 [iphone 4s] mainScreen.scale:2.000000
 [iphone 4s] mainScreen.brightness:0.500000


 


 


 


 


 


 


 

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6