Wrong AccentColor showing, color ignored

1.4k views Asked by At

I added a non-blue color named AccentColor to my iOS app’s assets catalogue. When running my app the tint color is default blue.

The “Global Accent Color Name” in build settings is correctly set to “AccentColor”. Do I need to set anything else? What setting could override this?

2

There are 2 answers

0
Jordan H On

I encountered this same issue in my app. It used to work but at some point all controls became tinted the default blue instead of my custom color. I confirmed Global Accent Color Name is correct in the target's build settings and that asset catalog is added to that target.

After a bunch of debugging, I found the cause. This line of code breaks the global accent color (tested with Xcode 14 beta 5):

UINavigationBar.appearance().largeTitleTextAttributes = [.font : UIFont(descriptor: UIFontDescriptor.preferredFontDescriptor(withTextStyle: .largeTitle).withDesign(.rounded)!.withSymbolicTraits(.traitBold)!, size: 34)]

However, something like this does not break it:

UINavigationBar.appearance().largeTitleTextAttributes = [.font: UIFont.systemFont(ofSize: 34)]

Super odd. If you have any UINavigationBar appearance overrides, try commenting them out to see if that's causing your issue.

And as a workaround, what I'm doing is setting the window's tintColor in the SceneDelegate (manually added for my SwiftUI app):

final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        (scene as? UIWindowScene)?.keyWindow?.tintColor = UIColor(named: "AccentColor")
    }
    
}
0
sergej shafarenka On

Not sure if the reason for your issue the same as mine, but I suddenly stumbled upon the same effect. Although AccentColor is defined in Assets and is bound to "Global Accent Color Name", previews and app felt back to standard blue color.

It turned out I instantiated a type extending UIViewController before calling WindowGroup. Even though the instance has not been used anywhere, it was enough to just instantiate it to break binding to "Global Accent Color Name". After postponing instantiation of the type to after WindowGroup is called, the accent color binding started to work again.