【问题标题】:In Xcode 13 [[UINavigationBar appearance] setBarTintColor: not working properly?在 Xcode 13 [[UINavigationBar 外观] setBarTintColor: 无法正常工作?
【发布时间】:2021-11-21 10:39:43
【问题描述】:

我已将我的 Xcode 更新为 13,后来我的旧项目导航和标签栏颜色更改为透明。

我的代码是

[[UINavigationBar appearance] setBarTintColor:[UIColor AppThemeColour]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];

我尝试添加背景颜色,但没有出现导航栏的标题和图像。

self.navigationController.navigationBar.backgroundColor = [UIColor bOneAppThemeColor];
[[UINavigationBar appearance] setBarTintColor:[UIColor AppThemeColour]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];

我已经研究了下面的链接,但我无法在 Objective C 中实现它

https://developer.apple.com/forums/thread/682420

【问题讨论】:

    标签: ios objective-c xcode uinavigationcontroller uinavigationbar


    【解决方案1】:

    您所做的几乎所有事情都是错误的(并且已经错了好几年)。您需要使用 UINavigationBarAppearance(和 UITabBarAppearance)并将它们应用于栏的standardAppearance 和它的scrollEdgeAppearance。设置外观的背景颜色,而不是它的色调颜色。并且永远不要碰translucent 属性。

    在这个简单的示例中,我们让所有导航栏都采用您的主题颜色。修改以满足您的需要和愿望:

    if (@available(iOS 13.0, *)) {
        UINavigationBarAppearance* appear = [UINavigationBarAppearance new];
        appear.backgroundColor = [UIColor AppThemeColor];
        id proxy = [UINavigationBar appearance];
        [proxy setStandardAppearance: appear];
        [proxy setScrollEdgeAppearance: appear];
    } else {
        // Fallback on earlier versions
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-04
      • 1970-01-01
      • 1970-01-01
      • 2018-07-14
      • 2021-08-30
      相关资源
      最近更新 更多