更改ios8扩展导航栏颜色

问题描述 投票:8回答:3

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

我尝试过这些方法来更新导航栏颜色,但是失败了:

[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor blueColor]];

它显示默认的半透明灰色导航栏。

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

ios objective-c ios8
3个回答
7
投票

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

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

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

希望你觉得它有用。


0
投票

尝试将UINavigationBar的半透明度设置为NO,如下所示,我相信它应该开始拾取颜色

[[UINavigationBar appearance] setTranslucent:NO];

这是Apple Documentation for UINavigationBar translucent property


-2
投票

我已将您的代码放在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;
}

并且工作......

© www.soinside.com 2019 - 2024. All rights reserved.