How to create and use a Color Set in XCode
In the Assets, right click and select "New Color Set." Then define your light and dark mode colors using the inspector on the right hand side.
The example can be found on the main branch of our SwiftUI Open Source Starter Project linked below.
Step One: Create
Select the Assets folder in your project and under the definitions, right click and select New Color Set from the menu that pops up.
Step Two: Name
Name the Color Set. Press the Enter key when done.
Please note that you must NOT name color sets "Red", "Green", "Primary" or "Background" as these conflict with the Apple System definitions. Apple has yet to provide a means for developers to alter the standard color scheme.
Step Three: Define
Select the relevant color (i.e. Any Appearance for Light mode or Dark for Dark Mode) and using the inspector on the right hand side, set the relevant color.
Step Four: Declare and use.
To use a Color Set, use the following syntax - where "COLOR_NAME" is the name that you set in step two:
Color("COLOR_NAME")
We recommend declaring the colors in a color struct and offering them as part of a styleguide.
Follow the tutorial below to learn more.
Looking to learn more about SwiftUI, Swift, Design and Technology?
Search our blog to learn more about Swift, SwiftUI, design and technology.