Zorgan
Zorgan

Reputation: 9153

SwiftUI's TabView colour cannot change to a custom colour

Here is my 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:

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

it always defaults to the system orange (equivalent to Color.orange)

My custom orange is #ff8000.

Is the tab bar color limited to the system colors?

Upvotes: 2

Views: 1233

Answers (1)

Asperi
Asperi

Reputation: 258345

Works fine with Xcode 12 / iOS 14. It is a tint (not pure) color (if you use picker to test result). To have pure assigned color you have to disable translucency

    UITabBar.appearance().isTranslucent = false

Upvotes: 4

Related Questions