iOS 13 - 导航栏标题颜色问题

标签 ios uinavigationcontroller ios13 xcode11

我有一个带有多个 viewController 和一个 tabBarController 的 Storyboard应用程序。到目前为止,navigationBar 的标题颜色为白色。现在我正在使用 Xcode 11 beta 6 和 iOS 13 beta 8 进行测试,标题为黑色。在装有 iOS 12 的设备上,标题仍然是白色的。
我试图在 Storyboard的导航 Controller 的导航栏中设置标题颜色。但这没什么区别。
我还尝试在每个 View 中更改标题颜色,但有时不起作用。
在开始使用 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];

我希望有人知道如何将标题颜色改回白色。无需调整每个 Controller 的最佳情况。

最佳答案

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

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

关于iOS 13 - 导航栏标题颜色问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57610454/

相关文章:

ios - 将日期格式化为固定宽度且不补零

ios5如何通过prepareForSegue : a UIImageView

objective-c - 单点触控设备只会崩溃

ios - 模态下的弹出/推送 View

swift - iOS 13 自定义字体下载和安装

ios - (SWIFT 3) 创建父子托管对象上下文

ios - Collection View 单元格导航

iphone - 插入另一个 View Controller 后,如何将按钮添加到导航 Controller 右侧?

iOS 13 替代 'setAnimationCurve'

ios - 如何从 iOS 13 上的 LPMetadataProvider 获取图像?