更改ios8扩展导航栏颜色 [英] Change ios8 Extension Navigation Bar color

查看:289
本文介绍了更改ios8扩展导航栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发iOS8 App Extension(照片编辑扩展程序)

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.

有没有人知道如何更改iOS8扩展中的导航栏颜色?

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

推荐答案

首先尝试 self.navigationController.navigationBar.barTintColor = [UIColor yellowColor];
这适用于某些主机应用程序但不是全部。因为一些主机应用程序在UIAppearance设置中配置颜色。

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.

我在这里找到了一些信息: https://pspdfkit.com/blog/2017/action-extension/

根据上面的链接,扩展名将选择从其主机应用程序启动UIAppearance设置,这比您发送给实例的setColor消息具有更高的优先级。

I found some info in here: https://pspdfkit.com/blog/2017/action-extension/
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.

所以你可以做的是配置扩展的plist:

NSExtension 您可以在字典中指定密钥 NSExtensionOverridesHostUIAppearance 并将值设置为 YES 。这将使您的扩展程序覆盖主机应用程序的UIApprearance设置。不幸的是,这仅适用于iOS 10及更高版本。

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.

希望您觉得它有用。

这篇关于更改ios8扩展导航栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆