在新的SwiftUI中,类型Color
与UIKit
中的UIColor
非常相似.
正如预期的那样,有几种常见的 colored颜色 ,但我注意到还有另外两种 colored颜色 :
.primary
.secondary
苹果的文档中没有关于不同Color
的描述.
- What are these colors?
- Which one should I use for certain things?
在新的SwiftUI中,类型Color
与UIKit
中的UIColor
非常相似.
正如预期的那样,有几种常见的 colored颜色 ,但我注意到还有另外两种 colored颜色 :
.primary
.secondary
苹果的文档中没有关于不同Color
的描述.
与UIColor
相比,SwiftUI似乎不完整.初级和次级指的是text colors,即UIColor.label
和UIColor.secondaryLabel
.
一个简单的扩展,提供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..
}