5

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?

Jane Trifels
  • 115
  • 1
  • 7
  • https://medium.com/@priya_talreja/accentcolor-in-swiftui-setting-app-theme-58347682ba54 - this should work. Sometimes Xcode is a bit "buggy" when it comes to changes in the assets catalog. Then it might help clearing the build folder (cmd k and or cmd shift k). – DoTryCatch Feb 21 '22 at 21:48
  • In your Mac's System Preferences – General – AccentColor has to be set to multicolor – ChrisR Feb 21 '22 at 21:56
  • Developing for iOS, updated the question. Clearing build folder didn’t change anything. Still blue. – Jane Trifels Feb 21 '22 at 22:09
  • `.tint` actually overrides the AccentColor in the asset catalogue. You don't have to use it – if you set a custom AccentColor in asset catalogue everything should have it. – ChrisR Feb 21 '22 at 22:16
  • Really weird. Nowhere in my app I am setting `.tintColor`. Only set AccentColor in my assets catalogue to green, still have blue tint/accent in my app (device and sim). – Jane Trifels Feb 21 '22 at 22:25
  • @JaneTrifels I checked it successfully with my Xcode. Is your Mac up to date? Is your Xcode updated? Is you testing device up to date? Did you removed the default AccentColor form the assets catalog or did you just changed the color? If you removed the color empty your bin and try it again. – DoTryCatch Feb 21 '22 at 22:41
  • @DoTryCatch Yes, tried all of that. Nothing works. What a mess. – Jane Trifels Feb 22 '22 at 14:30
  • @JaneTrifels could you please add a screenshot of your assets catalog with the color etc.? Maybe that helps. – DoTryCatch Feb 22 '22 at 14:46

2 Answers2

1

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")
    }
    
}
Jordan H
  • 52,571
  • 37
  • 201
  • 351
0

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.

sergej shafarenka
  • 20,071
  • 7
  • 67
  • 86