包含在多个类中的iOS 6外观 [英] iOS 6 appearance when contained in multiple classes
问题描述
我在我想要在iOS 6应用中自定义的某些UI元素上使用 appearanceWhenContainedIn
方法。我发现的问题是,如果我尝试提供多个容器类,则不会应用任何自定义项,如下所示:
I’m using the appearanceWhenContainedIn
method on certain UI elements that I want to customise in my iOS 6 app. The problem I found is that none of my customisations are applied if I try to provide more than one container class, like so:
// Works neither for toolbar nor navbar items
[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], [UIToolbar class], nil]
// Works fine (but only for navbar items, obviously)
[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
官方文档说明这个方法的参数可以是一个nil终止的多个类列表,但在我的情况下,它永远不会按照它应该的方式工作。我在这里遗漏了什么吗?
The official docs say that the parameter for this method can be a nil-terminated list of multiple classes, but in my case it never works the way it should. Am I missing something here?
推荐答案
来自文档:
appearanceWhenContainedIn:
...
给定包含
层次结构中接收者的外观代理。
The appearance proxy for the receiver in a given containment hierarchy.
这实际上意味着没有-terminated list不定义UIBarButtonItem的容器类列表,而是从上到下定义容器层次结构,所以
That actually means that nil-terminated list defines not the list of the container classes for UIBarButtonItem, but container hierarchy from top to bottom, so
[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], [UIToolbar class], nil]
返回里面的UIBarButtonItem的外观代理UINavigationBar和UINavigationBar依次在UIToolbar中。
returns appearance proxy for UIBarButtonItem that is inside UINavigationBar, and UINavigationBar in turn is inside UIToolbar.
或
[[UIBarButtonItem appearanceWhenContainedIn:[UIToolbar class],[ViewController class], nil] setTintColor:[UIColor redColor]];
为ViewController类中任何UIToolBar中的UIBarButtonItems设置红色色调。
set red tint color for UIBarButtonItems that are in any UIToolBar which are in ViewController class.
因此,要分别为UINavigationBar和UIToolBar设置外观,您需要对 + appearanceWhenContainedIn:
方法进行2次单独调用
So to set appearance for UINavigationBar and UIToolBar separately you'll need 2 separate calls to the +appearanceWhenContainedIn:
method
这篇关于包含在多个类中的iOS 6外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!