Reputation: 470
I am working on iOS8 App Extension (Photo Editing Extension)
I have tried these method to update the Navigation Bar color, but failed:
[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor blueColor]];
It displays a default translucent gray nav bar.
Does anybody have idea on how to change the navigation bar color in iOS8 extension?
Upvotes: 9
Views: 3194
Reputation: 1297
Try self.navigationController.navigationBar.barTintColor = UIColor.yellow
first.
This should work for some host apps but not all. Because some host apps configure the colors in UIAppearance settings.
I found some info in here: https://pspdfkit.com/blog/2017/action-extension/#uiappearance
According to the link above, the extension will "picks up the UIAppearance settings from its host app" and this has a higher priority than the "setColor" message you send to the instance.
In this case what you can do is to modify the plist of the extension:
In NSExtension
dictionary you can add a key NSExtensionOverridesHostUIAppearance
and set value to YES
. This will make your extension override the UIApprearance setting of the host app. Unfortunately this is only available in iOS 10 and later.
Hope you find it helpful.
Upvotes: 10
Reputation: 1363
I have put your code in the appDelegate didFinishLaunchWithOption
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor blueColor]];
return YES;
}
And works...
Upvotes: -2
Reputation: 12093
Try setting the translucency of the UINavigationBar
to NO
like below, I believe then it should start picking up the colours
[[UINavigationBar appearance] setTranslucent:NO];
Here's the Apple Documentation for UINavigationBar
translucent
property
Upvotes: 0