【问题标题】:UITabBar not changing tint color Xcode 9.3UITabBar不改变色调Xcode 9.3
【发布时间】:2018-07-12 21:35:15
【问题描述】:

这很奇怪。我的全局色调已设置,我的图标颜色设置为我拥有的默认紫色。然而在运行时它是蓝色的。有小费吗?我查了一下,没有看到其他人遇到这个问题。

故事板:

运行时间:

【问题讨论】:

    标签: ios iphone swift xcode uitabbarcontroller


    【解决方案1】:

    基本上,当您想以编程方式更改UITabBar 的色调颜色时,UITabBar 类为您提供了几个色调颜色属性:

    • tintColorTabBarItem 的颜色。
    • barTintColor : TabBar 的背景栏颜色。
    • unselectedItemTintColor : 未选中项的颜色。

    所以如果你改变tintColor,barItems的颜色就会改变。


    ...但是,为什么它在 IB 上不起作用?

    当您在 IB 中为 UITabBar 的项目设置特定颜色时,有一个名为 Image Tint 的选项。

    在“查看”部分更改 Tint 选项不会影响 TabBar 的项目,但只有 Image Tint 选项可以更改 tabBar 的项目颜色。

    storyboard的全局tint color选项改变了“View”部分的Tint选项,但不影响Image Tint选项的默认值,所以不会影响tab bar的tint颜色。


    那么.. 为什么Image Tint 选项不受影响?

    我无法解释为什么它不受影响。也许 Apple 遇到了这个问题,或者某种错误。


    有一些设置图像颜色的解决方法:

    • 为 UITabBarController 的 TabBar 对象显式设置 Image Tint 选项。

    您可能应该设置每个TabBarControllerImage Tint 选项,因为它不会影响全局设置。

    • 以编程方式更改全局 UITabBar 的 tintColor。

    AppDelegate.swiftdidFinishLaunchingWithOptions,粘贴以下代码

    UITabBar.appearance().tintColor = <#Color what you want#>
    

    【讨论】:

      【解决方案2】:

      我遇到了类似的问题,已通过将“呈现为”属性更改为“默认”而不是“原始”来解决此问题。在属性检查器的“渲染为”下的右侧选择图像时,您可以在资源库中找到它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-11-24
        • 1970-01-01
        • 1970-01-01
        • 2015-05-21
        • 2015-06-03
        • 1970-01-01
        • 2011-12-26
        相关资源
        最近更新 更多