Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change ios8 Extension Navigation Bar color

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.

default nav. color

Does anybody have idea on how to change the navigation bar color in iOS8 extension?

like image 290
David Ng Avatar asked Sep 03 '14 11:09

David Ng


1 Answers

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.

like image 92
jokeman Avatar answered Oct 16 '22 05:10

jokeman