iOS 获取状态栏,自定义状态栏视图

方法1:_staWindow是UIWindow类型,必须声明为全局变量

··· CGRect rect = [UIApplication sharedApplication].statusBarFrame;
_staWindow = [[UIWindow alloc]initWithFrame:rect];
_staWindow.backgroundColor = [UIColor redColor];
//windowLevel有三个等级,normal会形成状态栏的底色,其余两个等级(StatusBar,Alert)会遮盖住状态栏
_staWindow.windowLevel = UIWindowLevelNormal;
//必须设置不可隐藏,否则会不显示当前遮盖视图
_staWindow.hidden = NO;···

方法2:局部变量遮盖法,效果一样
···CGRect rect = [UIApplication sharedApplication].statusBarFrame;
UIView *view = [[UIView alloc]initWithFrame:rect];
view.hidden = NO;
view.backgroundColor = [UIColor redColor];
UIWindow *win = [UIApplication sharedApplication].keyWindow;···
等级大于等于1000(status等级)即可遮盖
··· win.windowLevel = 1000;
[win addSubview:view];···

你可能感兴趣的:(iOS 获取状态栏,自定义状态栏视图)