【问题标题】:How can I change a UIBarButtonItem's TintColor when building for iOS 6.1 and running under iOS 7?在为 iOS 6.1 构建并在 iOS 7 下运行时,如何更改 UIBarButtonItem 的 TintColor?
【发布时间】:2013-09-23 17:42:11
【问题描述】:

我有一个使用 6.1 SDK 编译的 iOS 应用程序,其中包含一些 UIBarButtonItems,其中 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 过渡指南后,我尝试设置 UIWindow 的 TintColor 以查看这是否有效果。它没有。

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

如果我不能在 iOS 7.0 下以编程方式更改 TintColor,我正在考虑为按钮创建自定义背景图像,就像这样。

并使用 SetBackgroundImage 覆盖现有背景。

提前致谢。

更新 - 09.24.13

poupou 的回答将我指向 WWDC 视频 (link),它在 8:37 为我提供了解决方案 - 我需要设置导航栏的 TintColor 而不是设置特定按钮的 TintColor。

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

【问题讨论】:

    标签: iphone xamarin.ios ios7 uibarbuttonitem tintcolor


    【解决方案1】:

    我尝试设置 UIWindow 的 TintColor 以查看是否有效果。它没有。

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

    WWDC 2013 的整个会议(第 214 场)关于 TintColor 以及它在 iOS7 中的工作原理(即井字游戏示例)。

    如果您需要运行/排除某些特定于 iOS 版本的代码,您可以这样做:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 2020-03-04
      • 2021-12-14
      • 2013-10-16
      • 2013-10-10
      • 1970-01-01
      相关资源
      最近更新 更多