Wrong AccentColor showing, color ignored
Asked Answered
T

2

7

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?

Thracophrygian answered 21/2, 2022 at 21:33 Comment(8)
medium.com/@priya_talreja/… - 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).Calices
In your Mac's System Preferences – General – AccentColor has to be set to multicolorZoophyte
Developing for iOS, updated the question. Clearing build folder didn’t change anything. Still blue.Thracophrygian
.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.Zoophyte
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).Thracophrygian
@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.Calices
@Calices Yes, tried all of that. Nothing works. What a mess.Thracophrygian
@JaneTrifels could you please add a screenshot of your assets catalog with the color etc.? Maybe that helps.Calices
N
4

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")
    }
    
}
Nuriel answered 23/8, 2022 at 15:17 Comment(0)
R
2

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.

Rozalin answered 12/8, 2023 at 14:27 Comment(1)
Thank you. My problem was that. I was creating viewcontroller for splash as class property. Converting it to lazy, fixed the problem.Philips

© 2022 - 2024 — McMap. All rights reserved.