xcode 包含在多个类中时的 iOS 6 外观
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12592025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS 6 appearance when contained in multiple classes
提问by Arnold
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:
我在appearanceWhenContainedIn
我想在我的 iOS 6 应用程序中自定义的某些 UI 元素上使用该方法。我发现的问题是,如果我尝试提供多个容器类,则不会应用任何自定义,如下所示:
// 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]
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?
官方文档说这个方法的参数可以是多个类的以 nil 结尾的列表,但在我的情况下,它从来没有像它应该的那样工作。我在这里错过了什么吗?
回答by Vladimir
From the docs:
从文档:
appearanceWhenContainedIn:
...
The appearance proxy for the receiver in a given containment hierarchy.
出现时包含在:
...
给定包含层次结构中接收器的外观代理。
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
这实际上意味着 nil-terminated list 定义的不是 UIBarButtonItem 的容器类列表,而是从上到下的容器层次结构,所以
[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], [UIToolbar class], nil]
returns appearance proxy for UIBarButtonItem that is inside UINavigationBar, and UINavigationBar in turn is inside UIToolbar.
返回 UINavigationBar 内的 UIBarButtonItem 的外观代理,而 UINavigationBar 又在 UIToolbar 内。
or
或者
[[UIBarButtonItem appearanceWhenContainedIn:[UIToolbar class],[ViewController class], nil] setTintColor:[UIColor redColor]];
set red tint color for UIBarButtonItems that are in any UIToolBar which are in ViewController class.
为 ViewController 类中的任何 UIToolBar 中的 UIBarButtonItems 设置红色色调。
So to set appearance for UINavigationBar and UIToolBar separately you'll need 2 separate calls to the +appearanceWhenContainedIn:
method
因此,要分别设置 UINavigationBar 和 UIToolBar 的外观,您需要对该+appearanceWhenContainedIn:
方法进行2 次单独的调用