2012-09-15 58 views
1

我使用此代碼來自定義我的導航欄圖像,貫穿我的應用程序。UIPopoverController導航欄外觀

UIImage *navBarTexture = [[UIImage imageNamed:@"NavBarTexture_iPad"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
    [[UINavigationBar appearance] setBackgroundImage:navBarTexture forBarMetrics:UIBarMetricsDefault]; 
    [[UINavigationBar appearance] setBackgroundImage:navBarTexture forBarMetrics:UIBarMetricsLandscapePhone]; 

這有效。但是,在UIPopoverControllers的導航欄上使用此圖像時,看起來有點奇怪。蘋果的默認圖像是我想要使用的,我怎樣才能讓它保留原來的外觀?

我知道我可以使用appearanceWhenContainedIn:但是如果我返回零作爲圖像,我只是得到一個黑色的空間。

任何幫助非常感謝,謝謝。

回答

2

我想到的第一件事就是在定製之前從導航欄中獲取默認圖像。我很震驚,它的工作。

UINavigationBar *appearanceProxBar = [UINavigationBar appearance]; 
UIImage *defaultImage = [appearanceProxBar backgroundImageForBarMetrics:UIBarMetricsDefault]; 
[appearanceProxBar setBackgroundImage:navBarTexture forBarMetrics:UIBarMetricsDefault]; 
[[UINavigationBar appearanceWhenContainedIn:[UIPopoverController class], nil] setBackgroundImage:defaultImage forBarMetrics:UIBarMetricsDefault]; 

而且,正如你可以在答案看到,WWDC 2012 - 216 - iOS上的高級外觀定製了鑄造外觀代理到相應的類,所以編譯器可以警告的一個實例的絕招無法識別的選擇器,並且代碼完成更加精確。

+0

很酷它像魅力一樣工作.... –

+0

它不適用於ios 6中的MFMailComposeViewController類。有任何想法爲什麼? – rowwingman

+0

@rowwingman它不起作用,因爲'MFMailComposeViewController'完全呈現在不同的過程中。 –