In the new SwiftUI, the type Color
is very similar to UIColor
from UIKit
.
There are the common colors, as expected, but there is the addition of two other colors that I noticed:
.primary
.secondary
There is nothing in the Apple Documentation for the descriptions of the different Color
s.
SwiftUI provides with multiple ways to initialize colors. One way to do it is using Color(red: ..., green: ..., blue: ...) . You can provide the RGB (Red, Green, blue) value on a 0-1 range. You can also initialize color with UIColor (from UIKit) and NSColor (from AppKit).
primary is the default color of text in SwiftUI, and will be either black or white depending on whether the user's device is running in light mode or dark mode.
SwiftUI seems to be incomplete compared to what is provided by UIColor
. The primary and secondary refers to the text colors, which are the UIColor.label
and UIColor.secondaryLabel
.
A simple extension to provide more UIColor
:
public extension Color { static let lightText = Color(UIColor.lightText) static let darkText = Color(UIColor.darkText) static let label = Color(UIColor.label) static let secondaryLabel = Color(UIColor.secondaryLabel) static let tertiaryLabel = Color(UIColor.tertiaryLabel) static let quaternaryLabel = Color(UIColor.quaternaryLabel) static let systemBackground = Color(UIColor.systemBackground) static let secondarySystemBackground = Color(UIColor.secondarySystemBackground) static let tertiarySystemBackground = Color(UIColor.tertiarySystemBackground) // There are more.. }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With