Change the status bar background color color past iOS 7

前端 未结 8 1352
既然无缘
既然无缘 2020-12-30 04:02

I want to change background color of status bar on iOS 7, and I\'m using this code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOp         


        
8条回答
  •  悲哀的现实
    2020-12-30 04:57

    While handling the background color of status bar in iOS 7, there are 2 cases

    Case 1: View with Navigation Bar

    In this case use the following code in your viewDidLoad method

      UIApplication *app = [UIApplication sharedApplication];
      CGFloat statusBarHeight = app.statusBarFrame.size.height;
    
      UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, -statusBarHeight, [UIScreen mainScreen].bounds.size.width, statusBarHeight)];
      statusBarView.backgroundColor = [UIColor yellowColor];
      [self.navigationController.navigationBar addSubview:statusBarView];
    

    Case 2: View without Navigation Bar

    In this case use the following code in your viewDidLoad method

     UIApplication *app = [UIApplication sharedApplication];
     CGFloat statusBarHeight = app.statusBarFrame.size.height;
    
     UIView *statusBarView =  [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, statusBarHeight)];
     statusBarView.backgroundColor  =  [UIColor yellowColor];
     [self.view addSubview:statusBarView];
    

提交回复
热议问题