1

I have a SwiftUI 5.3 Multiplatform app in Xcode 12.2 on MacOS 11.01 running on iOS 14.2 that uses a custom color asset for light/dark modes. When starting up the app, it functions perfectly fine alternating between light and dark modes. All the colors change accordingly.

However, when in dark mode, if I move the app to the background and bring another app to the foreground, then go back to my app (restoring from being in the background), the TabView color washes out completely. The NavigationView at the top functions normally, as expected at all times. If I then switch to light mode, the correct light mode color appears for the TabView. Switching back to dark mode restores the correct dark mode TabView colors. If I again move the app to the background, look at another app, then bring my app back to the foreground, the TabView color is again washed out.

I haver tried countless things with color calls using init and .onAppear, but nothing has corrected this behavior.

Any thoughts? Thanks for taking the time to help me sort this out.

Edited for added clarity. Code is added here:

import SwiftUI

struct TabbedView: View {
    
    init() {
        UINavigationBar.appearance().titleTextAttributes = [NSMutableAttributedString.Key.foregroundColor:UIColor(named: "mainTextColor") as Any]
        UINavigationBar.appearance().barTintColor = UIColor(named: "barBackground")
        UINavigationBar.appearance().tintColor = UIColor(named: "mainTextColor")
        UITabBar.appearance().isOpaque = true
        UITabBar.appearance().unselectedItemTintColor = UIColor(named: "unselectedTabColor")
        UITabBar.appearance().barTintColor = UIColor(named: "barBackground")
    }
    
    var body: some View {
        
        TabView {
            
            ContentView()
                .tabItem {
                    VStack {
                        Image("Topics69x69")
                        Text("Topics")
                    }
            }.tag(0)
            
            ChangesView()
                .tabItem {
                    VStack {
                        Image("Changes69x69")
                        Text("Changes")
                    }
            }.tag(1)
            
            GospelView()
                .tabItem {
                    VStack {
                        Image("Gospel69x69")
                        Text("Gospel")  
                    }
            }.tag(2)
            
            CopyrightView()
                .tabItem {
                    VStack {
                        Image("Copyright75x75")
                        Text("Copyright")
                    }
            }.tag(3)
            
            AboutView()
                .tabItem {
                    VStack {
                        Image("About75x75")
                        Text("About")
                    }
            }.tag(4)
            
        } // TabView

        // Sets color of the selected tab on the TabBar
        .accentColor(Color("tabImageTintColor"))
        
    } // View
    
} // Main View
dmiannay
  • 115
  • 1
  • 2
  • 10
  • 1
    Would you show your code? – Asperi Nov 22 '20 at 04:59
  • Thanks for your reply, nicksarno. I am not familiar with the variable. I understood that iOS handles color scheme under the hood. This works just fine in UIKit and I don’t have code to check for what scene is active. Can you explain? – dmiannay Nov 22 '20 at 23:50
  • @nicksarno - Can you please explain why this would be necessary? I am using color sets in the Asset Catalog since I understand colors change automatically when changing back and forth between light and dark modes. Do I also need to add the Environment variable to get this to work correctly? – dmiannay Feb 03 '21 at 20:02
  • Hi @Asperi - I did add the code as requested. Any idea why the dark mode color gets washed out? – dmiannay Feb 03 '21 at 20:03
  • Hey @dmiannay, have you found a way to solve this issue? I think I have the exact same one: https://stackoverflow.com/questions/66445366/swiftui-2-0-tabview-tab-bar-colors-dont-respect-the-current-color-scheme-dar?noredirect=1#comment117467552_66445366 – alpennec Mar 18 '21 at 17:24

0 Answers0