在新的SwiftUI中,类型ColorUIKit中的UIColor非常相似.

正如预期的那样,有几种常见的 colored颜色 ,但我注意到还有另外两种 colored颜色 :

  • .primary
  • .secondary

苹果的文档中没有关于不同Color的描述.

  • What are these colors?
  • Which one should I use for certain things?

推荐答案

UIColor相比,SwiftUI似乎不完整.初级和次级指的是text colors,即UIColor.labelUIColor.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..
}

Swift相关问答推荐

可编码:将字符串解码为自定义类型(ISO 8601日期,无时间组件)

如何使用快速宏用来自函数的关联值来初始化枚举?

如何返回JSON数据?

如何在SWIFT中轻松格式化公制和英制使用的UnitVolume

按变换zoom 在UIView中不起作用

为SwiftUI文本视图提供固定宽度,并仅在文本换行时使文本视图底部增大

仅当单击UIButton时才调用计时器函数

MacOS 13-如何使用SwiftUI创建Message.App设置工具栏?

SwiftUI-如何使用剩余时间制作倒计时计时器

在 SwiftUI 中禁用 Select 器选项

Swift Random Float Fatal Error:在无限范围内没有均匀分布

Swift 全局函数列表

如何 for each 用户制作一个单独的按钮,以便在按下它时切换 isFollowingUser Bool 并更改为关注?

如何在 Swift 中将 XPC 自定义类列入白名单?

在swift 3中将文件保存在文档目录中?

Swift 中惰性 var 的优势是什么

Type 应该采用什么协议来让泛型函数将任何数字类型作为 Swift 中的参数?

如何在 Swift 中遍历 struct 属性?

WKWebView 确实从本地文档文件夹加载资源

无法将 NSAttributedString.DocumentAttributeKey 类型的值转换为 .DocumentReadingOptionKey