事实上,就像@rickster 所说,appearanceWhenContainedIn: 方法自定义了包含在容器类实例中的类实例或层次结构中的实例的外观。
并非在每种情况下,您都有一组要自定义的包含类,而是不同的容器。能够自定义多个组件的解决方案是简单地创建一个您需要自定义和迭代的类数组!像这样:
NSArray *navigationClass = [NSArray arrayWithObjects:[BSNavigationController class], [DZFormNavigationController class], nil];
for (Class class in navigationClass)
{
//// Customize all the UINavigationBar background image tilling
[[UINavigationBar appearanceWhenContainedIn:class, nil] setBackgroundImage:[UIImage imageNamed:@"yourImage"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:class, nil] setTintColor:[UIColor blackColor]];
// Title Text Attributes
NSDictionary *titleAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor darkGrayColor], UITextAttributeTextShadowColor,
[UIFont boldSystemFontOfSize:20.0], UITextAttributeFont,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,nil];
//// Customize all the UINavigationBar title attributes
[[UINavigationBar appearanceWhenContainedIn:class, nil] setTitleTextAttributes:titleAttributes];
}