Reputation: 491
I have a storyboard-app with several viewControllers and a tabBarController. Up to now the color of the title of the navigationBar was white. Now I'm testing with Xcode 11 beta 6 an iOS 13 beta 8 and the title are black. On devices with iOS 12 the title are still white. I tried to set title color in the navigation bar of the navigation controller in the storyboard. But this makes no difference. I also tried to change the title color in every view, but sometimes it doesn't work. At the beginning of testing with iOS 13 I had to change my code for changing the backgroundcolor of the statusbar. The code is this:
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];
I hope anyone has an idea how to change the title color back to white. Best case without adjust every controller.
Upvotes: 8
Views: 6113
Reputation: 1607
In iOS 13, I change the title color like this
UINavigationBarAppearance *appearance = [self.navigationController.navigationBar standardAppearance];
appearance.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
self.navigationController.navigationBar.standardAppearance = appearance;
self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
Upvotes: 4
Reputation: 612
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
}
}
//call this function in your AppDelegate also in a class where you want navigation to work like this
Upvotes: 10
Reputation: 493
iOS 13 uses dynamic color for light and dark themes you can set the title color by creating a color asset for light and dark appearance.
Upvotes: 0
Reputation: 125
In iOS13 you need to set the title color on the UINavigationBarAppearance object - try adding this line to your code:
appearance.titleTextAttributes = [.foregroundColor: myAppLabelColor]
appearance.largeTitleTextAttributes = [.foregroundColor: myAppLabelColor]
Upvotes: 1