标签:
1 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIWindow : UIView 2 @available(iOS 2.0, *) public class UIWindow : UIView
Objective-C
1 // 声明窗口视图 2 @property (strong, nonatomic) UIWindow *window; 3 4 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 5 6 // 实例化窗口视图,window 的大小和当前手机屏幕一样大 7 self.window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds]; 8 9 // 设置 window 的背景颜色 10 self.window.backgroundColor = [UIColor whiteColor]; 11 12 // 将窗口显示到屏幕上 13 [self.window makeKeyAndVisible]; 14 15 return YES; 16 }
Swift
1 // 声明窗口视图 2 var window: UIWindow? 3 4 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 5 6 // 实例化窗口视图,window 的大小和当前手机屏幕一样大 7 self.window = UIWindow(frame: UIScreen.mainScreen().bounds) 8 9 // 设置 window 的背景颜色 10 self.window?.backgroundColor = UIColor.whiteColor() 11 12 // 将窗口显示到屏幕上 13 self.window?.makeKeyAndVisible() 14 15 return true 16 }
不同型号的 iOS 设备的屏幕尺寸:
Type | width | height | inch |
---|---|---|---|
iPhone 6(s) Plus | 414 | 736 | 5.5 |
iPhone 6(s) | 375 | 667 | 4.7 |
iPhone 5(s/c) | 320 | 568 | 4.0 |
iPhone 4(s) | 320 | 480 | 3.5 |
iPhone SE | 320 | 568 | 4.0 |
iPad Pro | 1024 | 1366 | 12.9 |
iPad Retina | 768 | 1024 | 9.7 |
iPad Air (2) | 768 | 1024 | 9.7 |
iPad 2 | 768 | 1024 | 7.9 |
Objective-C
1 // 当前屏幕的宽度 2 CGFloat width = [UIScreen mainScreen].bounds.size.width; 3 4 // 当前屏幕的高度 5 CGFloat height = [UIScreen mainScreen].bounds.size.height;
Swift
1 // 当前屏幕的宽度 2 let width:CGFloat = UIScreen.mainScreen().bounds.size.width 3 4 // 当前屏幕的高度 5 let height:CGFloat = UIScreen.mainScreen().bounds.size.height
标签:
原文地址:http://www.cnblogs.com/QianChia/p/5734330.html