一、UIApplication
1.打开网页
// URL:资源路径
// URL:协议头://域名+路径 http,https,file,tel
// 协议头:
// 打开网页 @"http://www.baidu.com"
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
[[UIApplication sharedApplication] openURL:url]; //跳到Safari打开网页
2.隐藏状态栏
// 获取UIApplication
UIApplication *app = [UIApplication sharedApplication];
// 隐藏状态栏
// [app setStatusBarHidden:YES];
[app setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
// 在iOS7以后,状态栏默认由控制器决定
// 隐藏状态栏
//- (BOOL)prefersStatusBarHidden
//{
// return YES;
//}
//- (UIStatusBarStyle)preferredStatusBarStyle
//{
// return UIStatusBarStyleLightContent;
//}
3.设置提醒数字
// 1.整个app中只有一个UIApplication
// UIApplication *app = [[UIApplication alloc] init];
UIApplication *app = [UIApplication sharedApplication];
// 2.UIApplication一般用来做一些应用级别的操作(app的提醒框,联网状态,打电话,打开网页,控制状态栏)
// UIApplication *app1 = [UIApplication sharedApplication];
// 设置appIcon提醒数字,必须注册用户通知
app.applicationIconBadgeNumber = 10;
// 创建用户通知
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
// 注册用户的通知
[app registerUserNotificationSettings:settings];
// 设置联网状态
app.networkActivityIndicatorVisible = YES;
二、UIWindow
1.AppDelegate.h中的window属性
// 程序启动完成的时候
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 1.创建窗口,注意窗口必须要有尺寸,尺寸跟屏幕一样大的尺寸,窗口不要被释放
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor redColor];
// 2.创建窗口的根控制器
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor yellowColor];
[vc.view addSubview:[UIButton buttonWithType:UIButtonTypeContactAdd]];
// 如果设置窗口的根控制器,默认就会把控制器的view添加到窗口上
// 设置窗口的根控制器,默认就有旋转功能
self.window.rootViewController = vc;
// [self.window addSubview:vc.view];
// 3.显示窗口
[self.window makeKeyAndVisible];
return YES;
}
2.窗口是有层级关系
UIWindowLevelNormal < UIWindowLevelStatusBar < UIWindowLevelAlert
// 设置窗口的层级关系
self.window1.windowLevel = UIWindowLevelStatusBar;