1

UIPickerViewサブクラス内にビューがありUINavigationControllerます。UIAppearanceサブクラスに含まれる多くのビューに適用したいプロキシがありますが、を で操作しUINavigationControllerたくありません。UIAppearanceUIPickerView

UIAppearanceサブクラス内のすべてのビューにプロキシを適用し、UINavigationController特定のオブジェクト内のビューをその影響から保護する方法はありますか?

UIAppearance がない場合、画面は次のようになります。

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

画面は次のようになります。

UIAppearance あり

UINavigationController に含まれる他の多くのビューにシアンを適用したいかもしれませんが、UIPickerview のサブビューがシアンによって破壊されるのは望ましくありません。

4

1 に答える 1

0

何を達成しようとしているのか正確にはわかりませんが、コードで何が起こっているかを次に示します。

ナビゲーションコントローラー内ですべてのビューの背景色をシアンに設定しています。UIPickerView はビューなので、色が変更されます。

編集:

外観プロトコルは、実際に必要なものに対しておそらくやり過ぎだと思います。ピッカー ビューの背後にあるビューの色を変更したい場合は、先に進んでその背景色を設定してください。

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

特定のビューのすべてを特定の色に変更したい場合は、外観プロトコルがうまく機能します。たとえば、すべてのナビゲーション バーを赤色にしたい場合、これを 1 か所に設定すると、アプリケーション内のすべてのナビゲーション バーが変更されます。

これが機能するためには、その青色にしたいすべてのビューをサブクラス化し、それらをアピアランス プロトコル メソッド AppearanceWhenContainedIn で設定する必要があります。

于 2013-05-18T20:44:56.457 に答える