Protect class from UIAppearance
我在
进行操作
有没有办法让
没有UIAppearance,屏幕看起来像这样:
使用此代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #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; } |
屏幕看起来像这样:
我不希望 UIPickerview 的子视图被青色破坏,尽管我可能想将青色应用于 UINavigationController 中包含的许多其他视图。
我不确定您到底要完成什么,但这是您的代码发生的情况。
您将导航控制器内的所有视图背景颜色设置为青色。 UIPickerView 是一个视图,所以它的颜色发生了变化。
编辑:
我认为外观协议可能对您真正想要的东西来说太过分了。您想更改选择器视图后面的视图颜色,然后继续设置其背景颜色。
1 | [[self YOUR_VIEW] setBackgroundColor:[UIColor blueColor]]; |
如果您想将特定视图的所有内容更改为特定颜色,则外观协议效果很好。例如,您希望所有导航栏都为红色,您可以将其设置在一个位置,它会更改应用程序中的所有导航栏。
为此,您必须将所有您想要为蓝色的视图子类化,并使用外观协议方法 appearanceWhenContainedIn 设置它们。