Change ios8 Extension Navigation Bar color

不打扰是莪最后的温柔 提交于 2019-12-08 17:06:10

问题


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?


回答1:


Try self.navigationController.navigationBar.barTintColor = [UIColor yellowColor]; 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.

So what you can do is configuring the plist of the extension:
In NSExtension dictionary you can specify the 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.




回答2:


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




回答3:


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...



来源:https://stackoverflow.com/questions/25642796/change-ios8-extension-navigation-bar-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!