swiftuser-interfaceswiftuiaccent-color

How do I stop the AccentColor from turning Gray when a sheet is being presented?


When a sheet is presented in SwiftUI, my AccentColor (set in the asset catalog) turns gray on the view behind the sheet. Is there a way to disable this so that the AccentColor is always the set color, and does not change to gray when in the background?

I’ve noticed that if I use Color(“AccentColor”) the color doesn’t turn gray, but if I use Color.accentColor it does turn gray.


Solution

  • Color.accentColor reflects the accent color of the system or app, it is a broad theme color applied to views and controls, so it relies on SwiftUI's default behavior, which may lead to the color being adjusted to match the background context. When you explicitly code Color("AccentColor") you are basically overriding this, that is why the color remains consistent. I guess you are not supposed to disable anything; you just need to define your own custom accent color.