iOS5改变UIToolbar的背景
我已阅读“iOS 5 中的新增功能”文档,其中指出,现在可以更好地支持更改某些 UI 元素的背景。
我找不到 iOS 5 更改 UIToolbar 背景图像的正确方法。 iOS 5 是否有一种特殊的新方法可以做到这一点?或者我仍然需要子类化 UIToolbar 吗?
I've read the "What's new in iOS 5" documentation and there it is stated, that changing the background of some UI-Elements is now better supported.
I couldn't find the correct way for iOS 5 to change the background image of an UIToolbar. Is there a special new iOS 5 way of doing this? Or do i still have to subclass the UIToolbar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,有一种新方法可以做到这一点。您可以使用
appearance
使所有UIToolBar
具有相同的外观。首先,您必须确保您的类遵循 UIAppearanceContainer 协议。我在我的应用程序委托中完成了它:
然后,您可以在例如
application:didFinishLaunchingWithOptions:
或viewDidLoad
中设置外观。像这样:您只需执行一次此操作即可为应用中的所有 UIToolBar 获得相同的外观。您还可以设置
UIToolBar
的许多(如果不是全部?)属性。顺便说一句,有许多类可以遵循 UIAppearanceContainer 协议。要了解使用外观协议可以定制哪些内容,可以打开要定制的类的头文件,如果可以用
UIAppearance
设置一个属性,那么该属性就有UI_APPEARANCE_SELECTOR
写在属性声明后面。Yes, there is a new way to do this. You can use
appearance
to make allUIToolBar
s have the same appearance.First, you have to make sure your class follows the
UIAppearanceContainer
protocol. Here I have done it in my app delegate:Then you can set the appearance in, for example,
application:didFinishLaunchingWithOptions:
orviewDidLoad
. Like this:You only have to do this once to get the same appearance for all
UIToolBar
s in your app. You can also set many of (if not all?) the properties of yourUIToolBar
.As a sidenote, there are many classes that can follow the
UIAppearanceContainer
protocol. To find out what can be customized using the appearance protocol, you can open the header file of the class you want to customize, if you can set a property withUIAppearance
, then the property hasUI_APPEARANCE_SELECTOR
written behind the property declaration.这是一个很棒的教程: http://www.raywenderlich.com/ 4344/user-interface-customization-in-ios-5
基本上,它看起来像这样:
Here's a great tutorial: http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5
Basically, it looks like this: