Swift
// 当应用程序启动后将会调用该方法
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
// 创建UIWindow对象,并初始化该窗口的大小与主屏幕大小相同
let rect : CGRect = UIScreen.mainScreen().bounds
// 程序将创建的UIWindow对象赋值给该程序委托对象的window属性
self.window = UIWindow(frame:rect)
// 创建ViewController对象、并使用ViewController界面布局文件来
// 初始化该视图控制器关联的用户界面
let vc = ViewController(nibName: "ViewController", bundle: nil)
// 让该程序的窗口加载、并显示viewController视图控制器关联的用户界面
self.window?.rootViewController = vc
//设置背景颜色
self.window?.backgroundColor = UIColor.whiteColor()
// 将该UIWindow对象设为主窗口、并显示出来
self.window?.makeKeyAndVisible()
return true
}
Objective-C
// 当应用程序启动后将会调用该方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// 创建UIWindow对象,并初始化该窗口的大小与主屏幕大小相同
CGRect rect = [[UIScreen mainScreen] bounds];
// 程序将创建的UIWindow对象赋值给该程序委托对象的window属性
self.window = [[UIWindow alloc] initWithFrame:rect];
// Override point for customization after application launch.
// 创建FKViewController对象、并使用FKViewController界面布局文件来
// 初始化该视图控制器关联的用户界面
ViewController *vc = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
// 让该程序的窗口加载、并显示viewController视图控制器关联的用户界面
self.window.rootViewController = vc;
//设置背景颜色
self.window.backgroundColor = [UIColor whiteColor];
// 将该UIWindow对象设为主窗口、并显示出来
[self.window makeKeyAndVisible];
return YES;
}