Color
extension Color
-
从16进制创建Color
Declaration
Swift
public static func color(_ hex: Int, _ alpha: Double = 1) -> Color
Parameters
hex
十六进制值,格式0xFFFFFF
alpha
透明度可选,默认1
Return Value
Color
-
从RGB创建Color
Declaration
Swift
public static func color(_ red: Double, _ green: Double, _ blue: Double, _ alpha: Double = 1) -> Color
Parameters
red
红色值
green
绿色值
blue
蓝色值
alpha
透明度可选,默认1
Return Value
Color
-
从十六进制字符串初始化,支持RGB、RGBA|ARGB,格式:"20B2AA", “#FFFFFF",失败时返回clear
Declaration
Swift
public static func color(_ hexString: String, _ alpha: Double = 1) -> Color
Parameters
hexString
十六进制字符串
alpha
透明度可选,默认1
Return Value
Color
-
几乎透明的颜色,常用于clear不起作用的场景
Declaration
Swift
public static var almostClear: Color { get }
-
获取透明度为1.0的RGB随机颜色
Declaration
Swift
public static var randomColor: Color { get }
-
Color转换为UIColor,失败时返回clear
Declaration
Swift
public func toUIColor() -> UIColor
Return Value
UIColor