Culore
为 UIColor 和 NSColor 实现了命名颜色预设,支持超过 300 种官方定义的颜色!
用法
将 Culore 导入到项目中如下
import Culore
由于 Culore 扩展了 UIColor 和 NSColor,因此必须导入 UIKit 或 Cocoa 才能使用它。
// iOS, tvOS, and watchOS
import UIKit
// macOS
import Cocoa
iOS, tvOS 和 watchOS
let newColor = UIColor.culore("orange")
macOS
let newColor = NSColor.culore("orange")
颜色
查找颜色
访问维基百科中的色彩变体页面(例如:橙色的不同色调)或Culore支持的色彩列表这里,找到你喜欢的颜色。
输入颜色
通过提供给 .culore() 方法的字符串字面量来生成颜色,该方法扩展了 UIColor/NSColor。
let newColor = UIColor.culore("orange")
⚠️ 关键⚠️
- 忽略标点和括号。
orange (pantone) => orange pantone
hooker's green => hookers green
- 用空格、下划线或破折号分隔颜色的名称中的单词。
uranian blue == uranian-blue == uranian_blue
- 如果顺序重要,从名称中删除空格或破折号。
blue-green => bluegreen
green-blue => greenblue
- 将带重音符号的字符替换为其最接近的无重音等效物。
café noir => cafe noir
说明
- 您可以以任意顺序提供颜色名称。
UIColor.culore("pantone orange") == UIColor.culore("orange pantone")
- 大小写不影响。
sky blue == SkY bLuE == SKY BLUE
不支持的颜色
并非所有命名颜色都受支持;在这些情况下,Culore 返回 nil。在您使用之前,请始终检查您的颜色。
if let newColor = UIColor.culore("orange") {
myLabel.textColor = newColor
}
未来的更新将在经过验证和测试后将支持更多颜色。
安装
CocoaPods
要使用 CocoaPods 将 Culore 整合到您的 Xcode 项目中,请在您的 Podfile
中指定它。
pod 'Culore'
然后运行 pod install
。
要求
- iOS 9.0+、tvOS 9.0+、watchOS 2.0+ 或 macOS 10.9+
- Swift 5.0+
- CocoaPods
许可证
MIT 许可证