What are the .primary and .secondary colors in SwiftUI?

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..
}

However, a huge drawback is that the colors will not automatically change between light & dark modes.

The above code is only for iOS, while macOS/AppKit does not have corresponding lightText etc.

Therefore, a better solution is to define such colors in Assets Catalog.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)