A Swift Extension for UIColor supporting iOS/watchOS/tvOS and macOS.
.package(url: "https://github.com/icodesign/SwiftColor.git", from: "1.5.0")
Add SwiftColor
to your Cartfile
:
github "icodesign/SwiftColor"
Add SwiftColor
to your Podfile
:
pod 'SwiftColor'
You can also integrate SwiftColor
directly with souce code. Just copy SwiftColor.swift
to your project.
SwiftColor
provides a typealias forUIColor
/NSColor
asColor
.
Supported hex string format:
RGB
,RGBA
,[0x|#]RRGGBB
,[0x|#]RRGGBBAA
Color("000")
Color("000C")
Color("0x4DA2D9")
Color(hexString: "#4DA2D9")
Color(hexString: "#4DA2D9CC")
Color(hexString: "#4DA2D9", alpha: 0.8)
"#4DA2D9CC".color
Only hex format
0xRRGGBB
is supported
Color(hexInt: 0x4DA2D9)
Color(hexInt: 0x4DA2D9, alpha: 0.8)
(0x4DA2D9).color
Color(byteRed: 77, green: 162, blue: 217, alpha: 0.8)
let color = Color(hexString: "#4DA2D9CC")
// get color components
var (r, g, b, a) = color.colorComponents()
// change color components
var red = "000".color.red(255)
var alphaColor = Color(hexInt: 0x4DA2D9).alpha(0.8)
let image = "000".color.toImage()