iphone - 在为 iOS 6.1 构建并在 iOS 7 下运行时,如何更改 UIBarButtonItem 的 TintColor?

标签 iphone xamarin.ios ios7 uibarbuttonitem tintcolor

我有一个使用 6.1 SDK 和一些 UIBarButtonItems 编译的 iOS 应用程序,其中 TintColor 在 ViewWillAppear 中以编程方式设置。

UIBarButtonItem leftButton = new UIBarButtonItem(...);
leftButton.TintColor = UIColor.FromRGB(231, 231, 231);

结果是这样的。

Custom UIBarButtonItem TintColor on 6.1

我已将 iPhone 升级到 7.0,但仍需要针对 6.1 SDK 进行构建以实现向后设备兼容性(商业原因)。

当我使用 6.1 SDK 构建应用程序并在运行 iOS 7.0 的 iPhone 上运行它时,工具栏如下所示。

Custom UIBarButtonItem TintColor on 7.0

阅读完 iOS 7 UI Transition Guide 后,我尝试设置 UIWindow 的 TintColor 来看看是否有效果。但事实并非如此。

有趣的是 - 在此表单上,当我显示 ActionSheet 时,在 ActionSheet 关闭后,“取消”和“保存”按钮的背景从“黑色”更改为“白色”。我目前正在调查为什么会发生这种情况。

如果我无法在 iOS 7.0 下以编程方式更改 TintColor,我正在考虑为按钮创建自定义背景图像,如下所示。

Greyish Button

并使用SetBackgroundImage覆盖现有背景。

提前致谢。

更新 - 2013 年 9 月 24 日

poupou 的回答让我引用了 WWDC 视频 (link),该视频在 8:37 给了我解决方案 - 我需要设置导航栏的 TintColor,而不是设置特定按钮的 TintColor。

NavigationBar.TintColor = UIColor.FromRGB(231, 231, 231);

最佳答案

I tried setting the UIWindow's TintColor to see if this had an effect. It did not.

它应该 - 但如果您在其他一些 UI 元素上设置 TintColor,那么它将优先于主 UIWindow 上设置的设置。

WWDC 2013(第 214 场 session )有一整场 session 讨论 TintColor 及其在 iOS7 中的工作原理(即井字游戏示例)。

如果您需要运行/排除某些特定于 iOS 版本的代码,您可以执行以下操作:

if (UIDevice.CurrentDevice.CheckSystemVersion (7,0)) {
    // iOS 7.0 and later
} else {
    // iOS 6.1 and earlier
}

关于iphone - 在为 iOS 6.1 构建并在 iOS 7 下运行时,如何更改 UIBarButtonItem 的 TintColor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18965548/

相关文章:

iphone - IOS CS193p - 为什么 IBAction 连接被拖到 .m 文件而不是 .h?

c# - 将音频从一台设备流式传输到另一台设备

xamarin - Apple 开发者帐户团队未出现在 VS Mac 上

ios - 如何从 MonoTouch 中的不同项目加载图像文件

ios - 更改 UIActionSheet 样式在 iOS 7 中没有区别吗?

ios - 如何删除 UITableViewCell 滑动以删除弹跳

ios - 弹出窗口显示时色调颜色褪色

iphone - TableView无法正确显示并崩溃,

iphone - iOS UILocalNotification 不更新应用程序图标

iphone - 什么是 UINavigationTransitionView