在 2011 年技术演讲中,我看到了一个关于新 UIAppearance 协议.那里还没有很多文档.我将简短地总结一下我记得的内容,以解释我的问题来自哪里:
On the tech talk 2011 I saw a speech about the new UIAppearance protocol. There is not a lot of documentation out there yet. I will shortly summarize what I remember to explain where my question is coming from:
关于UIAppearance:
到目前为止,您必须在所有应用视图控制器中自定义每个导航栏(工具栏等)属性.使用新的外观属性,您可以只在一个地方为应用程序中的所有导航栏执行此操作.例如:如果您想自定义导航栏背景图像,您可以这样做:
So far you had to customize EVERY navigation bar (toolbar, etc.) property in all your app view controllers. With the new appearance property you can do it in only one place for all navigation bars in your app. For instance: if you want to customize your Navigation bar background image you could do it like this:
[[UINavigationBar appearance] setBackgroundImage:
[UIImage imageNamed:@"MyImageName"] forBarMetrics:UIBarMetricsDefault];
这将设置应用程序中所有导航栏的背景图像.使用 barMetrics 您可以指定是否要在横向模式下也使用图像.
This will set the background image of ALL navigation bars within your application. With the barMetrics you specify whether you want the image to be used also in landscape mode or not.
如果您想指定仅在某些视图控制器中应用的外观,文档中还有一种方法可以通过指定对象的位置来控制它:
If you want to specify the appearance to be applied only in some view controllers there is also a method in the docs to control that by specifying where your objects are located:
[[UIBarButtonItem appearanceWhenContainedIn:
[ABPeoplePickerNavigationController class], nil] setTintColor:myNavBarColor];
另外值得一提的是,如果您有单个自定义实例,与您的外观设置不同,这些实例将不受外观代理的影响.
Also worth to mention is, if you have single customized instances, differing from your appearance settings, theses instances will not be effected by the appearance proxy.
一些问题:
a) 我如何知道类的哪些属性与外观属性一起使用? 例如因为 UITableView 符合 UIAppearance 协议,所以我想我可以做类似的事情
a) How do I know which properties of a class work with the appearance property? For e.g. since UITableView conforms to the UIAppearance protocol I was thinking I could do something like
[[UITableView appearance] setBackgroundColor:mytableViewColor];
来操纵我所有表格视图的背景颜色,但我不能!
to manipulate the background color of all my table views, but I can't!
b) 是否有所有可使用外观属性操作的类的列表?
c) 在什么时候调用外观自定义? 我希望在运行时对外观属性进行更改,但不幸的是,这些更改没有发生.
c) At what point is the appearance customization being called? I was hoping to make changes threw the appearance property at runtime, but unfortunately the changes aren't taking place.
a) 我如何知道某个类的哪些实例与外观属性一起使用?例如因为 UITableView 符合 UIAppearance 协议,所以我想我可以做类似的事情
a) How do I know which instances of a class work with the appearance property? For e.g. since UITableView conforms to the UIAppearance protocol I was thinking I could do something like
您查看类的标题(以及所有超类的标题).UI_APPEARANCE_SELECTOR 旁边的任何方法都支持与 UIAppearance 代理一起使用.
You look in the header of the class (and the headers of all the superclasses). Any method that has UI_APPEARANCE_SELECTOR next to it is supported for use with the UIAppearance proxy.
[[UITableView appearance] setBackgroundColor:mytableViewColor];
backgroundColor 属性未使用 UIView.h 中的 UI_APPEARANCE_SELECTOR 修饰.因此,它在技术上不支持与外观代理一起使用.它可能会起作用,但(鉴于缺乏方法修饰)不能保证.
The backgroundColor property is not decorated with UI_APPEARANCE_SELECTOR in UIView.h. Thus it is not technically supported for use with the appearance proxy. It will probably work, but (given the lack of method decoration) isn't guaranteed to.
来自UIAppearance 协议参考:
要支持外观定制,类必须符合UIAppearanceContainer协议,相关访问器方法必须用UI_APPEARANCE_SELECTOR标记.
To support appearance customization, a class must conform to the
UIAppearanceContainerprotocol and relevant accessor methods must be marked withUI_APPEARANCE_SELECTOR.
(注意和相关的访问器方法必须标记..."[强调添加])
(note "and relevant accessor methods must be marked..." [emphasis added])
b) 是否有所有可使用外观属性进行操作的属性的列表?
b) Is there a list of all properties that are manipulatable with the appearance property?
是否有一个页面显示每个使用外观代理的设置器?我不知道,也没有办法在运行时构建列表.
Is there a single page showing every setter that works with the appearance proxy? I don't know of one, nor is there a way to build the list at runtime.
c) 在什么时候调用外观定制?我希望在运行时对外观属性进行更改,但不幸的是没有发生更改.
c) At what point is the appearance customization being called? I was hoping to make changes threw the appearance property at runtime, but unfortunately the changes aren't taking place.
您可以在执行期间的任何时候使用外观代理.直到下次调用这些视图的 -layoutSubviews 方法时,这些更改才会应用于受影响的视图.
You can use the appearance proxy at any point during execution. The changes won't be applied to the affected views until the next time those views have their -layoutSubviews method invoked.
这篇关于iOS 5:对 UIAppearance 感到好奇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
KIF:如何自动运行/压力测试 iOS 应用程序以找出罕KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?(KIF:如何自动运行/压力测试 iOS 应用程序以找出罕见 UI 错
UITableView:在混合单元格表视图静态和动态单元格UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合单元格表视图静态和动态单元格中
如何在 iOS 中删除 Safari 中的地址栏?How to remove Address Bar in Safari in iOS?(如何在 iOS 中删除 Safari 中的地址栏?)
在 iOS5 中从 CIImage 创建 UIImage 时遇到问题Having trouble creating UIImage from CIImage in iOS5(在 iOS5 中从 CIImage 创建 UIImage 时遇到问题)
获取所有相册的列表和每个相册的缩略图Get list of all photo albums and thumbnails for each album(获取所有相册的列表和每个相册的缩略图)
谁能帮我通过音频单元录制 iPhone 输出的声音Can anybody help me in recording iPhone output sound through Audio Unit(谁能帮我通过音频单元录制 iPhone 输出的声音)