2019 年更新
UIColor
现在提供静态属性来获取系统颜色。
Example:
UIColor.systemBlue
有关系统颜色的完整列表,请查看 UIKit 文档中的“标准颜色”页面:https://developer.apple.com/documentation/uikit/uicolor/standard_colors https://developer.apple.com/documentation/uikit/uicolor/standard_colors
旧答案
iOS 不提供以编程方式访问这些颜色的方法。
相反,将这些颜色添加到您自己的项目中非常简单。如果颜色在未来的 iOS 版本中发生变化(并且您想使用这些新颜色),您将需要更新您的应用程序。
在大多数情况下,这不是问题,因为应用程序出于品牌目的定义了自己的颜色。
enum SystemColor {
case red
case orange
case yellow
case green
case tealBlue
case blue
case purple
case pink
var uiColor: UIColor {
switch self {
case .red:
return UIColor(red: 255/255, green: 59/255, blue: 48/255, alpha: 1)
case .orange:
return UIColor(red: 255/255, green: 149/255, blue: 0/255, alpha: 1)
case .yellow:
return UIColor(red: 255/255, green: 204/255, blue: 0/255, alpha: 1)
case .green:
return UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
case .tealBlue:
return UIColor(red: 90/255, green: 200/255, blue: 250/255, alpha: 1)
case .blue:
return UIColor(red: 0/255, green: 122/255, blue: 255/255, alpha: 1)
case .purple:
return UIColor(red: 88/255, green: 86/255, blue: 214/255, alpha: 1)
case .pink:
return UIColor(red: 255/255, green: 45/255, blue: 85/255, alpha: 1)
}
}
}
使用示例:
myView.backgroundColor = SystemColor.blue.uiColor
如果您愿意,这些颜色也可以定义为UIColor
像这样:
extension UIColor {
static let systemBlue = UIColor(red: 0/255, green: 122/255, blue: 255/255, alpha: 1)
// etc
}
用法如下:
UIColor.systemBlue
人机界面指南中的颜色 https://developer.apple.com/ios/human-interface-guidelines/visual-design/color/