iOS-设置状态栏白色以及覆盖状态栏

iOS-设置状态栏白色以及覆盖状态栏

将状态栏设置为白色

首先, 在info.plist中添加一个标记.

View controller–based status bar appearance键值设置为NO

这个标记的意思是, 以application中设置状态栏为高优先级. 在viewController中设置状态栏 为低优先级. 设置了这个标记, 下面的方法才是有效的.

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];  

通过上面的代码将状态栏设置为白色.


覆盖状态栏

如何覆盖状态栏, 需要定义一个window, 将window的UIWindowLevel属性设置为UIWindowLevelStatusBar或者更改. 之后将window添加到屏幕上,完成覆盖.

typedef CGFloat UIWindowLevel;  
const UIWindowLevel UIWindowLevelNormal; // 0.0  
const UIWindowLevel UIWindowLevelAlert; // 2000.0  
const UIWindowLevel UIWindowLevelStatusBar; // 1000.0  

StatusBar的层级是1000 所以只需要将UIWindow层级设置为
UIWindowLevelAlert或者UIWindowLevelStatusBar即可
然后接下来在改变层级的UIWindow中放置View便可以遮挡状态栏的位置了

实现代码为:

//声明代码
@property (strong, nonatomic) UIWindow *windowBack;//背景视图

//实现
self.windowBack = [[UIWindow alloc]initWithFrame:SCREEN_BOUNDS];
self.windowBack.backgroundColor = [UIColor clearColor];
self.windowBack.rootViewController = [[UIViewController alloc]init];
self.windowBack.rootViewController.view.backgroundColor = [UIColor clearColor];
self.windowBack.windowLevel = UIWindowLevelAlert;
[self.windowBack makeKeyAndVisible];
posted @ 2015-09-21 14:02  AbeDay  阅读(1201)  评论(0编辑  收藏  举报