我在UINavigationController
的子类中的视图中有一个UIPickerView
。我有一个UIAppearance
代理,我希望将它应用于UINavigationController
子类中包含的许多视图,但我不希望UIAppearance
在UIPickerView
上操作。
有没有办法让UIAppearance
代理应用于UINavigationController
子类中的所有视图,然后保护特定对象中的视图不受其影响?
如果没有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;
}
屏幕如下所示:
尽管我可能希望将青色应用于UINavigationController中包含的许多其他视图,但我不希望UIPickerview的子视图受到青色的破坏。
发布于 2013-05-18 20:44:56
我不确定您到底想要实现什么,但以下是您的代码所发生的事情。
您正在将导航控制器内的所有视图背景颜色设置为青色。UIPickerView是一个视图,所以它的颜色改变了。
编辑:
我认为外观协议可能对你真正想要的东西有点过分了。您想要更改选取器视图后面的视图的颜色,然后继续并设置其背景颜色。
[[self YOUR_VIEW] setBackgroundColor:[UIColor blueColor]];
如果您想要将特定视图的所有内容更改为特定颜色,则外观协议工作得很好。例如,您希望所有导航栏都为红色,您可以在一个点上设置此颜色,这将更改应用程序中的所有导航栏。
要实现这一点,您必须将您希望的所有视图子类化为蓝色,并使用外观协议方法appearanceWhenContainedIn设置它们。
https://stackoverflow.com/questions/16628225
复制相似问题