Engineering
This article delves into a macOS bug that causes SwiftUI to disregard the AccentColor of your app. It provides a temporary solution to this issue as we await an official resolution from Apple.
Furkan Simsir
16 mrt. 2024
• 1 min read
If you've been developing a macOS app targeting macOS 11+ in SwiftUI, you might have encountered an issue regarding the global AccentColor's handling. In spite of defining the color in an asset catalog and setting its name as the value for ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME
in your project's build settings, the system in certain conditions fails to apply this color as the accent color of SwiftUI views and controls.
This affects various elements like selection color in a List, tint color for Buttons, TabView etc. Applying the accentColor
or tint
modifiers in SwiftUI doesn't help either.
What is more, altering the system accent color to another choice and back to multicolor temporarily fixes the problem until the next application launch.
The Bug
Interestingly, the issue seems to arise when NSColor.controlAccentColor
is called anywhere in the code. In AppKit, this color refers to the accent color defined by the app.
The Workaround
Removing this reference resolves the issue. If you still need the accent color as a NSColor
, you can use the following workaround
Use this solution until Apple fixes this issue.
Radar
We reported the bug to Apple with reference FB13688723.
References
Global accent color not respected. Apple Developer Forum.
https://forums.developer.apple.com/forums/thread/704905NSColor.controlAccentColor. Apple Developer Documentation.
https://developer.apple.com/documentation/appkit/nscolor/3000782-controlaccentcolor