简体   繁体   English

SwiftUI 的 TabView 颜色无法更改为自定义颜色

[英]SwiftUI's TabView colour cannot change to a custom colour

Here is my TabView :这是我的TabView

struct HomeView: View {
    let auth: UserAuth
    init(auth: UserAuth) {
        self.auth = auth
        UITabBar.appearance().barTintColor = UIColor(named: "CustomOrange")
        UITabBar.appearance().unselectedItemTintColor = UIColor.white.withAlphaComponent(0.6)
        UITabBar.appearance().autoresizesSubviews = true
        UITabBar.appearance().backgroundColor = UIColor(named: "CustomOrange")
    }
    
    var body: some View {
        ZStack {
                TabView(selection: $selectedTab) {
                    Settings(auth: auth)
                    .tabItem {
                        Image(systemName: "gear")
                        Text("Settings")
                    }.tag(0)

When I set the colour of my tabview bar to a custom orange:当我将 tabview 栏的颜色设置为自定义橙色时:

UITabBar.appearance().barTintColor = UIColor(named: "CustomOrange")

it always defaults to the system orange (equivalent to Color.orange )它始终默认为系统橙色(相当于Color.orange

My custom orange is #ff8000.我的自定义橙色是#ff8000。

Is the tab bar color limited to the system colors?标签栏颜色是否仅限于系统颜色?

Works fine with Xcode 12 / iOS 14. It is a tint (not pure) color (if you use picker to test result).适用于 Xcode 12 / iOS 14。它是一种淡色(非纯)颜色(如果您使用选择器来测试结果)。 To have pure assigned color you have to disable translucency要获得纯指定颜色,您必须禁用半透明

    UITabBar.appearance().isTranslucent = false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM