The Color Type & Asset Colors
Use system and custom colors from the asset catalog.
The Color Type & Asset Colors is a free SwiftUI Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SwiftUI Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Meet the Color Type
In SwiftUI, color is its own value: the Color type. You use it for text, shapes, and backgrounds alike. 🎨
Built-in System Colors
SwiftUI ships with ready-made colors like Color.red, blue, and green. They are perfect for quick styling while you learn.
Text("Hello")
.foregroundStyle(Color.red)Color Is a View
A Color can act as a view on its own, filling all the space it is given. Drop one in and it becomes a solid block.
Color.blue
.frame(width: 100, height: 100)Semantic Colors Adapt
Colors like Color.primary automatically flip for light and dark mode. They keep your text readable everywhere.
Text("Adapts")
.foregroundStyle(Color.primary)Tinting with Opacity
Need a softer shade? Call opacity on any color to make it partly transparent, from 0 (clear) to 1 (solid).
Color.green.opacity(0.3)Custom RGB Colors
For exact brand shades, build a color from red, green, and blue values between 0 and 1. Total control over the hue.
Color(red: 0.2, green: 0.6, blue: 0.9)The Asset Catalog
The Assets folder in your project stores reusable colors and images. Define a color once and reuse it across the whole app.
Naming an Asset Color
Add a Color Set in Assets and give it a clear name like BrandPrimary. That name becomes how you call it in code.
Using an Asset Color
Load any asset color by passing its name to Color("name"). SwiftUI looks it up in your catalog for you.
Text("Branded")
.foregroundStyle(Color("BrandPrimary"))Light & Dark Variants
An asset color can hold a different value for each appearance. Set Any and Dark variants and SwiftUI swaps them automatically.
One Source of Truth
Asset colors give you a single place to tweak your palette. Change the swatch once and every screen updates together. ✨
Quick Check
How do you use a color you defined in the asset catalog?
Recap: Color & Assets
You met the Color type: system colors, custom RGB, opacity, and named asset colors that adapt to light and dark. Nicely done!
Frequently asked questions
Is the “The Color Type & Asset Colors” lesson free?
Yes — the full text of “The Color Type & Asset Colors” is free to read here on the web, and the SwiftUI Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SwiftUI Academy course, upgrade to CoddyKit PRO.
What will I learn in “The Color Type & Asset Colors”?
Use system and custom colors from the asset catalog. You practise SwiftUI Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start SwiftUI Academy?
No prior experience is required. SwiftUI Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “The Color Type & Asset Colors” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this SwiftUI Academy lesson?
Yes. Every SwiftUI Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- The Color Type & Asset Colors
- Linear, Radial & Angular Gradients
- Built-in Shapes
- Stroke, Fill & overlay