2013-05-18 26 views
1

我有一個UIPickerViewUINavigationController的子類內的視圖。我有一個UIAppearance代理,我想要應用於包含在UINavigationController子類中的許多視圖,但我不希望UIAppearanceUIPickerView上運行。從UIAppearancearance保護類

有沒有辦法讓UIAppearance代理適用於UINavigationController子類中的所有視圖,然後保護特定對象內的視圖不受其影響?

沒有UIAppearance,屏幕看起來是這樣的:

Without UIAppearance

有了這個代碼:

#import "AppDelegate.h" 

@interface AppDelegate() 

@property (nonatomic, strong) UINavigationController *nvcMain ; 

@end 

@implementation AppDelegate 

@synthesize window ; 
@synthesize nvcMain ; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ; 
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main_ph" bundle:nil] ; 
    nvcMain = [sb instantiateInitialViewController] ; 
    window.rootViewController = nvcMain ; 
    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 

    id apprNVCView = [UIView appearanceWhenContainedIn:[UINavigationController class], nil] ; 
    [apprNVCView setBackgroundColor:[UIColor cyanColor] ]; 

    return YES; 
} 

屏幕看起來是這樣的:

With UIAppearance

我不不想要子視圖的UIPickerview被青色破壞,儘管我可能希望將青色應用於包含在UINavigationController中的許多其他視圖。

回答

0

我不確定你想要完成什麼,但是這裏是你的代碼發生了什麼。

您正在將導航控制器中的所有背景色設置爲青色。 UIPickerView是一個視圖,它的顏色發生了變化。

編輯:

我覺得外觀協議可能只是矯枉過正你真正想要的東西。您想更改選取器視圖背後的視圖顏色,然後繼續並設置其背景顏色。

[[self YOUR_VIEW] setBackgroundColor:[UIColor blueColor]]; 

外觀協議效果很好,如果你想對所有國家的某些觀點的改變,以一種特定的顏色。例如,您希望所有導航欄都是紅色,您可以將其設置爲一個點,並且它會更改應用程序中的所有導航欄。

爲此,您必須繼承所有您希望成爲藍色的視圖,並使用外觀協議方法appearanceWhenContainedIn設置它們。

+0

但是,UIPickerView也包含在UINavigationController中,所以它獲得了UIAppearance以及其他視圖。 –

+0

附上截圖,我有點困惑,你的意思是,你不能通過外觀代理自定義選擇器視圖 – Vikings

+0

我更新了原始帖子以包含代碼和截圖。 –