状态栏颜色修改

【状态栏颜色修改】//设置状态栏颜色- (void)setStatusBarBackgroundColor:(UIColor*)color {UIView*statusBar = [[[UIApplicationsharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"]; NSLog(@"statusBar.backgroundColor--->%@",statusBar.backgroundColor); if([statusBar respondsToSelector:@selector(setBackgroundColor:)]) { statusBar.backgroundColor = color; }}- (UIStatusBarStyle)preferredStatusBarStyle{returnUIStatusBarStyleLightContent; //白色}- (void)viewDidLoad { [superviewDidLoad]; //Y起点在导航条下面self.edgesForExtendedLayout =UIRectEdgeNone; //设置navigationItem返回的文字UIBarButtonItem*item = [[UIBarButtonItemalloc] initWithTitle:@""style:UIBarButtonItemStyleDonetarget:nilaction:nil]; self.navigationItem.backBarButtonItem = item; }-(void)viewWillAppear:(BOOL)animated{ [superviewWillAppear:animated]; //设置导航条透明度self.navigationController.navigationBar.translucent =NO; //不透明[[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:1]; //图标颜色为黑色[self.navigationController.navigationBar setTintColor:[UIColorblackColor]]; //导航栏背景颜色[self.navigationController.navigationBar setBarTintColor:[UIColorwhiteColor]]; //导航条下面的黑线self.navigationController.navigationBar.clipsToBounds =NO; //刷新状态栏背景颜色// [self setNeedsStatusBarAppearanceUpdate]; //设置状态栏颜色[selfsetStatusBarBackgroundColor:[UIColorblackColor]]; }//一定要在viewWillDisappear里面写,如果写在viewDidDisappear里面会出问题!!!!- (void)viewWillDisappear:(BOOL)animated{ [superviewWillDisappear:animated]; //为了不影响其他页面在viewDidDisappear做以下设置self.navigationController.navigationBar.translucent =YES; //透明[selfsetStatusBarBackgroundColor:[UIColorclearColor]]; }
作者:来宝
链接:https://www.jianshu.com/p/5c09c2700038
來源:
著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

    推荐阅读