在Xcode 11(测试版2)的Interface Builder中指定了条调颜色时,UITabBarItem图标未针对iOS 13正确着色

Jor*_*ood 6 interface-builder uitabbarcontroller uitabbaritem ios xcode11

在iOS 13模拟器上使用Xcode 11,beta 2运行UITabBarItems的颜色时,我遇到了问题。但是,当我通过Interface Builder指定自定义的条形颜色时,会得到以下信息:

选中的两个未选中项目图标都具有突出显示的颜色

如果我将Interface Builder中的“ Bar Tint”属性设置为除clear以外的任何选项,则选项卡栏中的所有项目图标均具有选定的颜色。设置为清除时,图标将正确着色。如果我在iOS 12模拟器中编译并运行,这些图标的颜色也会正确显示。

这似乎是Xcode 11中的错误,但也许我遗漏了一些东西?

Sam*_*uël 13

iOS 13中有一个新的外观API。要使用Xcode 11.0为标签栏项目的图标和文本正确着色,您可以像这样使用它:

    if #available(iOS 13, *) {
        let appearance = UITabBarAppearance()

        appearance.backgroundColor = .white
        appearance.shadowImage = UIImage()
        appearance.shadowColor = .white

        appearance.stackedLayoutAppearance.normal.iconColor = .black
        appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]

        appearance.stackedLayoutAppearance.selected.iconColor = .red
        appearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red]

        self.tabBar.standardAppearance = appearance

    } 
Run Code Online (Sandbox Code Playgroud)


mma*_*ckh 9

从表面上看,这似乎是一个错误,但是您可以通过在UITabBar实例上定义一个.unselectedItemTintColor来缓解它。

self.tabBar.unselectedItemTintColor = [UIColor lightGrayColor];
Run Code Online (Sandbox Code Playgroud)

  • 这可以缓解问题,我们将看看Apple是否已解决此问题!Xcode 11 beta 4仍然存在原始问题。 (2认同)

小智 7

使用IB中的属性字段“Image Tint”。

使用IB中的属性字段“Image Tint”