首頁  >  問答  >  主體

objective-c - 設定NavigationBar為全透明的時候,statusBarStyle無法設定為Light

當我push到將當前視圖控制器的navigationBar設定為全透明時,

- (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;
}

然而頂端的狀態欄是漆黑一片。
我的上一層VC也使用了preferredStatusBarStyle,但是顯示沒有問題,不同在於上一級VC隱藏了NavigationBar,而push到當前VC的時候是顯示NavigationBar的..
求解各位大神!

迷茫迷茫2706 天前762

全部回覆(1)我來回復

  • PHPz

    PHPz2017-05-02 09:34:46

    終於在stackoverflow找到對應的解答,加上下面這句
    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 ackleLightContent),
    and UIBarStyleDefault will give ack status bar text.

    Note that this applies even if you totally change the navigationBar’s

    color via its barTintColor.

    具體的連結:http://stackoverflow.com/ques...

    回覆
    0
  • 取消回覆