iOS13-NavigationBar标题颜色出现问题

时间:2019-08-22 13:26:08

标签: ios uinavigationcontroller ios13 xcode11

我有一个Storyboard-app,其中包含几个viewControllers和一个tabBarController。到目前为止,navigationBar标题的颜色为白色。现在,我正在使用Xcode 11 beta 6和iOS 13 beta 8进行测试,标题为黑色。在装有iOS 12的设备上,标题仍为白色。 我试图在情节提要中的导航控制器的导航栏中设置标题颜色。但这没有区别。 我还尝试在每个视图中更改标题颜色,但有时不起作用。 在使用iOS 13进行测试的开始,我不得不更改代码以更改状态栏的背景色。代码是这样的:

self.tabBarController.title = NSLocalizedString(@"AppTitle",nil);

NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor clearColor];
shadow.shadowOffset = CGSizeMake(0, 1);

[self.navigationController.navigationBar setBarTintColor:COLOR_HEADER_LIGHT];

if (@available(iOS 13, *))
{
    UINavigationBarAppearance *navBar = [[UINavigationBarAppearance alloc] init];
    navBar.backgroundColor = COLOR_HEADER_LIGHT;
    self.navigationController.navigationBar.standardAppearance = navBar;
    self.navigationController.navigationBar.scrollEdgeAppearance = navBar;
}
else
{
    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
        statusBar.backgroundColor = COLOR_HEADER_LIGHT;
    }
}

[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                 shadow, NSShadowAttributeName, FONT_MEDIUM_SIZE_18, NSFontAttributeName,
                                                                 COLOR_TEXT_WHITE, NSForegroundColorAttributeName, nil]];

[self.navigationController.navigationBar setTintColor:COLOR_TEXT_WHITE];

我希望任何人都有一个想法如何将标题颜色改回白色。最好的情况是不调整每个控制器。

4 个答案:

答案 0 :(得分:3)

在iOS 13中,我这样更改标题颜色

UINavigationBarAppearance *appearance = [self.navigationController.navigationBar standardAppearance];
appearance.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
self.navigationController.navigationBar.standardAppearance = appearance;
self.navigationController.navigationBar.scrollEdgeAppearance = appearance;

答案 1 :(得分:0)

在iOS13中,您需要在UINavigationBarAppearance对象上设置标题颜色-尝试将以下行添加到代码中:

appearance.titleTextAttributes = [.foregroundColor: myAppLabelColor]
appearance.largeTitleTextAttributes = [.foregroundColor: myAppLabelColor]

答案 2 :(得分:0)

iOS 13对明暗主题使用动态颜色,您可以通过为明暗外观创建颜色资源来设置标题颜色。

答案 3 :(得分:0)

func manageNavigationBar(){
        if #available(iOS 13.0, *){

            let navBarAppearance = UINavigationBarAppearance()
            navBarAppearance.configureWithOpaqueBackground()
            navBarAppearance.backgroundColor = UIColor(red: 0.6157, green: 0.3412, blue: 0.8588, alpha: 1.0)
            navBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
            navBarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
            UINavigationBar.appearance(whenContainedInInstancesOf: [UINavigationController.self]).standardAppearance = navBarAppearance
            UINavigationBar.appearance(whenContainedInInstancesOf: [UINavigationController.self]).scrollEdgeAppearance = navBarAppearance
        }
    }

//在您希望导航以这种方式工作的类中,也在AppDelegate中调用此功能