【问题标题】:SwiftUI TabView accentColor(:_) deprecatedSwiftUI TabView 口音颜色(:_) 已弃用
【发布时间】:2022-09-27 22:18:40
【问题描述】:

我有一个 tabView,我试图改变它的颜色。使用 AccentColor(:_) 有效,但将被弃用。

TabView {
            AppetizerListView()
                .tabItem {
                    Image(systemName: \"house\")
                    Text(\"Home\")
                }
            AccountView()
                .tabItem {
                    Image(systemName: \"person\")
                    Text(\"Account\")
                }
            OrderView()
                .tabItem {
                    Image(systemName: \"bag\")
                    Text(\"Order\")
                }
        }
        .accentColor(Color(\"brandPrimary\"))

相反,我尝试按照 Apple 的建议使用 .tint(:_) 但不起作用(它会构建但不会改变颜色)。

TabView {
            AppetizerListView()
                .tabItem {
                    Image(systemName: \"house\")
                    Text(\"Home\")
                }
            AccountView()
                .tabItem {
                    Image(systemName: \"person\")
                    Text(\"Account\")
                }
            OrderView()
                .tabItem {
                    Image(systemName: \"bag\")
                    Text(\"Order\")
                }
        }
        .tint(Color(\"brandPrimary\"))

我也尝试在每个 TabItem 中使用 .tint(_:) ,但它也不起作用。

知道发生了什么,或者在不使用不推荐使用的函数的情况下使我的代码按预期工作的正确方法是什么?

也许我以错误的方式使用色调

谢谢!

    标签: swiftui swiftui-tabview


    【解决方案1】:

    我已经找到了问题的解决方案,但我会将帖子留给有同样问题的任何人。

    您需要做的是转到 Assets 文件夹并将 AccentColor(它必须已经创建)定义为您希望栏的颜色。

    无需向 tabView 添加任何修饰符,它会自动以您在 Assets 文件夹中定义为 AccentColor 的颜色显示 tabView。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-12
      • 2020-12-03
      • 1970-01-01
      • 1970-01-01
      • 2021-06-01
      • 2022-01-20
      相关资源
      最近更新 更多