objective-c - 设置NavigationBar为全透明的时候,statusBarStyle无法设定为Light

 手机用户2502856555 发布于 2022-10-25 08:09

当我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的..
求解各位大神!

1 个回答
  • 终于在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 black status bar text (ie.
    UIStatusBarStyleDefault).

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

    具体的链接:http://stackoverflow.com/ques...

    2022-10-26 14:33 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有