Swiftpack.co - icodesign/SwiftColor as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by icodesign.
icodesign/SwiftColor 1.6.0
A Swift Extension for UIColor.
⭐️ 48
🕓 1 year ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/icodesign/SwiftColor.git", from: "1.6.0")

License platform Build Status codecov

A Swift Extension for UIColor supporting iOS/watchOS/tvOS and macOS.


Swift Package Manager

.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.


Color Initialization

SwiftColor provides a typealias for UIColor/NSColor as Color.

Initialize with Hex String

Supported hex string format: RGB, RGBA, [0x|#]RRGGBB, [0x|#]RRGGBBAA

Color(hexString: "#4DA2D9")
Color(hexString: "#4DA2D9CC")

Color(hexString: "#4DA2D9", alpha: 0.8)


Initialize with Hex Int

Only hex format 0xRRGGBB is supported

Color(hexInt: 0x4DA2D9)

Color(hexInt: 0x4DA2D9, alpha: 0.8)


Initialize with RGBA

Color(byteRed: 77, green: 162, blue: 217, alpha: 0.8)

Get/Change Color Components

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)

Convert color to image

let image = "000".color.toImage()


Stars: 48
Last commit: 1 year ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics