search

Home  >  Q&A  >  body text

objective-c - When setting NavigationBar to be fully transparent, statusBarStyle cannot be set to Light

When I push to set the navigationBar of the current view controller to be fully transparent,

- (void)viewDidLoad {
    [super viewDidLoad];
//     Do any additional setup after loading the view from its nib.
    //设定字体颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    //设定背景图片为空
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    //半透明
    //self.navigationController.navigationBar.translucent = YES;
    //
    //self.edgesForExtendedLayout = UIRectEdgeNone;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

However, the status bar at the top is completely black.
My upper-level VC also uses preferredStatusBarStyle, but there is no problem with the display. The difference is that the upper-level VC hides the NavigationBar, but when pushing to the current VC, the NavigationBar is displayed..
Please help me!

迷茫迷茫2771 days ago813

reply all(1)I'll reply

  • PHPz

    PHPz2017-05-02 09:34:46

    Finally found the corresponding answer on stackoverflow, and added the following sentence
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

    I discovered that if your ViewController is inside a
    navigationController then the navigationController’s
    navigationBar.barStyle determines the statusBarStyle.

    Setting your navigationBar’s barStyle to UIBarStyleBlackTranslucent
    will give white status bar text (ie. UIStatusBarStyleLightContent),
    and UIBarStyleDefault will give black status bar text (ie.
    UIStatusBarStyleDefault).

    Note that this applies even if you totally change the navigationBar’s
    color via its barTintColor.

    Specific link: http://stackoverflow.com/ques...

    reply
    0
  • Cancelreply