Reputation: 14073
An accentColor
can have an "Any Appearance" color and a "Dark Appearance" color. Lets say, I'm in light mode, how can I access the dark mode color programmatically without manually setting the color mode to dark mode?
Upvotes: 1
Views: 2049
Reputation: 258443
You need to resolve your named color to trait collection of dark style, like
.background(
Color(UIColor(named: "testColor")?.resolvedColor(with:
UITraitCollection(userInterfaceStyle: .dark)) ?? UIColor.darkText)
)
Tested with Xcode 12.4 / iOS 14.4
Note: tune to your color name and any default color to unwrap optional
Upvotes: 3