2014-09-03 90 views
8

我在iOS8上的應用程序擴展(照片編輯擴展)工作變化iOS8上擴展導航欄顏色

我曾嘗試這些方法來更新導航欄的顏色,但沒有成功

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

它顯示默認半透明灰色導航欄。

default nav. color

有誰知道如何改變iOS8上擴展導航欄的顏色的想法?

+0

你有沒有發現這是可能的? – Gruntcakes 2016-08-17 15:01:02

+0

還沒有。 @SausageMachine – 2016-08-18 06:17:44

+0

調用UINavigationBar.appearance()。barTintColor可以工作並更改顏色,但不會擴展到狀態欄。 http://stackoverflow.com/questions/39000941/how-to-apply-the-navigation-bar-color-to-the-status-bar-in-an-extension – Gruntcakes 2016-08-18 14:21:29

回答

0

嘗試UINavigationBar的透明度設置爲NO像下面,我認爲就應該開始拿起顏色

[[UINavigationBar appearance] setTranslucent:NO]; 

這裏的Apple Documentation for UINavigationBartranslucent property

+0

它不工作..我認爲這個問題是'[UINavigationBar外觀]'是不是訪問擴展標題欄的方式.. – 2014-09-03 13:05:16

+0

@DavidNg嘗試'[[[[自導航控制器] navigationBar]外觀] setTranslucent:NO];'並用其餘的替換一樣。 – Popeye 2014-09-03 14:54:09

+0

[[self navigationController] navigationBar]沒有外觀屬性,外觀是來自'UINavigationBar'類的instanceType。 – 2014-09-04 07:55:43

-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; 
} 

而且作品...

enter image description here

+1

它適用於應用程序,但不適用於應用程序擴展程序 – 2015-01-21 06:31:57

+0

適用於應用程序的主要部分,但不適用於擴展程序。 – 2015-03-25 18:30:32

4

首先嚐試self.navigationController.navigationBar.barTintColor = [UIColor yellowColor];。 這應該適用於某些主機應用程序,但不是全部。由於某些主機應用程序在UIAppearance設置中配置顏色。

我發現這裏的一些信息:https://pspdfkit.com/blog/2017/action-extension/
根據上面的鏈接,擴展將「拿起從主機應用程序的UIAppearance設置」,這具有更高的優先級比你發送給了「的setColor」消息實例。

所以你可以做的是配置擴展的plist中:
NSExtension字典,你可以指定密鑰NSExtensionOverridesHostUIAppearance和設定值來YES。這將使您的擴展覆蓋宿主應用程序的UIApprearance設置。不幸的是,這僅適用於iOS 10及更高版本。

希望你覺得它有幫助。