How do I Add a Global Accent Color to a SwiftUI 1.0 Project?

Mark Moeykens
Jun 25, 2020
In the WWDC 2020 session "What's new in SwiftUI", there is mention of a new Global Accent Color.

Now, when you create a new SwiftUI project in Xcode 12, you will see an AccentColor added to your Assets.xcassets folder.




What if I have an existing project? How do I add a global accent color?

Here's what you do:
  1. If you haven't already, add a named color to your asset catalog to represent your global accent color.
  2. Select your project (top-most item in your project navigator).
  3. With either your Project or Target selected, click on:
    1. Build Settings
    2. All
  4. Scroll down to the category "Asset Catalog Compiler - Options"
  5. There is a new entry there called "Global Accent Color Name". Double-click to the right of it and you can enter the same name you added in step 1 to the text entry box that shows up.



What do I do now?

That's it!

Now all SwiftUI views that have an accent color will take on your global accent color name.




Free SwiftUI Picture Book

6 comments

Richard Mullinix
Jan 6, 2021
I find the global accent color to be buggy. For example action sheets initial appear with incorrect accent color. Is this a known bug?
Richard Mullinix
Feb 19, 2021
Yep. There are numerous go-arounds. I was just pointing out this bug when using SwiftUI Global AccentColor approach presented in this article. The easiest "fix" is just manually set the accent color for the action sheets. I'm converting away from SceneDelegate entirely. Converted all my projects to using App protocol. So using SceneDelegate / UIWindow / window.tintColor / is a no-go. https://wwdcbysundell.com/2020/building-entire-apps-with-swiftui/