简体   繁体   English

更改 ios8 扩展导航栏颜色

[英]Change ios8 Extension Navigation Bar color

I am working on iOS8 App Extension (Photo Editing Extension)我正在开发 iOS8 App 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?有人知道如何更改 iOS8 扩展中的导航栏颜色吗?

Try self.navigationController.navigationBar.barTintColor = UIColor.yellow first.首先尝试self.navigationController.navigationBar.barTintColor = UIColor.yellow This should work for some host apps but not all.这应该适用于某些主机应用程序,但不是全部。 Because some host apps configure the colors in UIAppearance settings.因为某些主机应用程序在 UIAppearance 设置中配置颜色。

I found some info in here: https://pspdfkit.com/blog/2017/action-extension/#uiappearance我在这里找到了一些信息: 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.根据上面的链接,扩展程序将“从其主机应用程序中获取 UIAppearance 设置”,这比您发送给实例的“setColor”消息具有更高的优先级。

In this case what you can do is to modify the plist of the extension:在这种情况下,您可以做的是修改扩展名的 plist:
In NSExtension dictionary you can add a key NSExtensionOverridesHostUIAppearance and set value to YES .NSExtension字典中,您可以添加一个键NSExtensionOverridesHostUIAppearance并将值设置为YES This will make your extension override the UIApprearance setting of the host app.这将使您的扩展程序覆盖主机应用程序的 UIAppreaance 设置。 Unfortunately this is only available in iOS 10 and later.不幸的是,这仅适用于 iOS 10 及更高版本。

Hope you find it helpful.希望你觉得它有帮助。

Try setting the translucency of the UINavigationBar to NO like below, I believe then it should start picking up the colours尝试将UINavigationBar的半透明设置为NO如下所示,我相信它应该开始拾取颜色

[[UINavigationBar appearance] setTranslucent:NO];

Here's the Apple Documentation for UINavigationBar translucent property这是UINavigationBar translucent属性Apple 文档

I have put your code in the appDelegate didFinishLaunchWithOption我已将您的代码放入 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...和作品...

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM