ios - 如何通过外观协议(protocol)设置 UIBarButtonItem 的 tintColor?

标签 ios objective-c uibarbuttonitem uiappearance

我试图在整个项目中以编程方式为 UIBarButtonItems 设置 tintColor。我在打电话:

[UIBarButtonItem 外观]

但是,在查看 Apple 的文档后: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIBarButtonItem_Class/Reference/Reference.html

我没有找到用于设置 tintColor 的此类属性。我能找到的最接近的相关方法是:

setBackgroundImage:forState:barMetrics:
setBackgroundImage:forState:style:barMetrics:

但是,这两种方法都是为了设置实际的背景图像。难道不能通过 UIAppearance 简单地设置按钮的 tintColor 吗?

最佳答案

也许我没有正确理解这个问题。但是如果您查看您发布的链接,在任务 -> 自定义外观下,有一个名为 tintColor 的属性。

您只需将该属性设置为所需的颜色

[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];

这对你不起作用吗?

关于ios - 如何通过外观协议(protocol)设置 UIBarButtonItem 的 tintColor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14862991/

相关文章:

ios - 无法在 UINavigationController 上设置后退按钮

android - 如何为 iOS 和 Android 上的深度链接确定 native 应用程序的参数

ios - 将 Siesta 与非 Restful API 结合使用

ios - 使用 AFNetworking 2.0 发布时出现错误(Cocoa 错误 3840)(字符 0 周围的值无效)

objective-c - 如何从nsarray删除空格,方括号和“

iphone - 替代用法,例如。 CGPoint 代表一个范围

ios - 从 'NSPersistentStoreResult' 转换为无关类型 '[entity]' 总是失败

ios - 无法将 TableView @IBOutlet 连接到 Swift 2 中的 ViewController

ios - 在 iOS 7 中更改后退按钮会禁用滑动以返回导航

xcode - 我们如何在导航栏中的UIBarButtonItem中放置两行