【问题标题】:Change color of unselected icon in TabView (SwiftUI)更改 TabView (SwiftUI) 中未选中图标的颜色
【发布时间】:2020-04-24 08:58:50
【问题描述】:

如何在 TabView (SwiftUI) 中更改未选中图标(在屏幕截图上)的颜色?因为这个图标是不可见的

【问题讨论】:

    标签: colors swiftui


    【解决方案1】:

    您可以使用我的解决方案中的TabBarAccessorProgrammatically detect Tab Bar or TabView height in SwiftUI 来更改您需要的内容,如下面的演示所示。

    使用 Xcode 11.4 / iOS 13.4 测试

    TabView {
        Text("First View")
            .background(TabBarAccessor { tabBar in
                tabBar.unselectedItemTintColor = UIColor.red
            })
            .tabItem { Image(systemName: "1.circle") }
            .tag(0)
        Text("Second View")
            .tabItem { Image(systemName: "2.circle") }
            .tag(1)
    }
    

    更新:通过外观替换也可以使用

    init() {
        UITabBar.appearance().unselectedItemTintColor = UIColor.green
    }
    

    【讨论】:

    • 有效!谢谢!我可以在我的 View Struct 的 'init()' 方法中做类似的事情吗?更改背景的示例 'init() { UITabBar.appearance().barTintColor = MyColor.blackcolorUI }'
    猜你喜欢
    • 2020-12-03
    • 2022-08-12
    • 2019-11-28
    • 1970-01-01
    • 2020-07-03
    • 1970-01-01
    • 2020-05-15
    • 2014-03-03
    • 2022-12-20
    相关资源
    最近更新 更多