Greetings, traveler!
In SwiftUI, colors can be organized hierarchically to create a consistent and scalable color system. This hierarchical system typically includes primary, secondary, tertiary, quaternary, and quinary colors.
Each subsequent color will be less opaque. You can use any color you want, including custom presets, accent color, and system colors.
Let’s check out an example.
import SwiftUI
struct ContentView: View {
var body: some View {
Rectangle()
.fill(Color.red)
.frame(height: 80)
Rectangle()
.fill(Color.red.secondary)
.frame(height: 80)
Rectangle()
.fill(Color.red.tertiary)
.frame(height: 80)
Rectangle()
.fill(Color.red.quaternary)
.frame(height: 80)
Rectangle()
.fill(Color.red.quinary)
.frame(height: 80)
}
}
However, it is worth considering that this is not a Сolor
but a ShapeStyle
.
If you enjoyed this article, please feel free to follow me on my social media:
It might be interesting:
- Leveraging Enums for Flexible Button Styling in SwiftUI
- How to access UIHostingController from a SwiftUI View
- Simplifying Data Access in SwiftUI with @dynamicMemberLookup
- Three Practical Tools for Managing References and Detecting Memory Leaks in Swift
- Paging with Peek: Three Ways to Implement Paginated Scroll in SwiftUI