我有一个使用 6.1 SDK 和一些 UIBarButtonItems 编译的 iOS 应用程序,其中 TintColor 在 ViewWillAppear 中以编程方式设置。
UIBarButtonItem leftButton = new UIBarButtonItem(...);
leftButton.TintColor = UIColor.FromRGB(231, 231, 231);
结果是这样的。
我已将 iPhone 升级到 7.0,但仍需要针对 6.1 SDK 进行构建以实现向后设备兼容性(商业原因)。
当我使用 6.1 SDK 构建应用程序并在运行 iOS 7.0 的 iPhone 上运行它时,工具栏如下所示。
阅读完 iOS 7 UI Transition Guide 后,我尝试设置 UIWindow 的 TintColor 来看看是否有效果。但事实并非如此。
有趣的是 - 在此表单上,当我显示 ActionSheet 时,在 ActionSheet 关闭后,“取消”和“保存”按钮的背景从“黑色”更改为“白色”。我目前正在调查为什么会发生这种情况。
如果我无法在 iOS 7.0 下以编程方式更改 TintColor,我正在考虑为按钮创建自定义背景图像,如下所示。
并使用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/