Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swift

swiftui

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

  • What are these colors?
  • Which one should I use for certain things?
like image 447
George Avatar asked Jun 05 '19 18:06

George


People also ask

What colors are available in SwiftUI?

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

What is primary color in SwiftUI?

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.


1 Answers

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.. } 
like image 179
samwize Avatar answered Oct 02 '22 04:10

samwize