Search code examples
iosobjective-cuinavigationcontrolleruinavigationbarstatusbar

How to change background color of status bar but not that of navigation bar?


RootVc: enter image description here

PushVc: enter image description here

How to implement this effect?

How to change the background color of the status bar but not that of the navigation bar?


Solution

  • Add this method to your every viewcontroller, or (Call it from category method)

    -(void)status_bar_color
    {
          if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
          {
                UIView *addStatusBar = [[UIView alloc] init];
                CGSize result = [[UIScreen mainScreen] bounds].size;
                if(result.height >750)
                {
                      addStatusBar.frame = CGRectMake(0, 0, 800, 23);
                }
                else if(result.height >550)//IPod
                {
                      addStatusBar.frame = CGRectMake(0, 0, 320, 23);
                }
                else
                {
                      addStatusBar.frame = CGRectMake(0, 0, 320, 23);
                }
    
                addStatusBar.backgroundColor=[UIColor blackColor];
                [self.view addSubview:addStatusBar];
          }
    }
    

    For the light content of statusbar, use this method also,

    -(UIStatusBarStyle)preferredStatusBarStyle
    {
          return UIStatusBarStyleLightContent;
    }
    

    Cool..