Latest 1.4.0
Homepage https://github.com/icodesign/SwiftColor
License MIT
Platforms ios 8.0, osx 10.10, watchos 2.0, tvos 9.0, requires ARC
Authors

License
platform
Build Status
codecov

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

Installation

Carthage

Add SwiftColor to your Cartfile:

github "icodesign/SwiftColor"

CocoaPods

Add SwiftColor to your Podfile:

pod 'SwiftColor'

Manually

You can also integrate SwiftColor directly with souce code. Just copy SwiftColor.swift to your project.

Usage

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("000")
Color("000C")
Color("0x4DA2D9")
Color(hexString: "#4DA2D9")
Color(hexString: "#4DA2D9CC")

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

"#4DA2D9CC".color

Initialize with Hex Int

Only hex format 0xRRGGBB is supported

Color(hexInt: 0x4DA2D9)

Color(hexInt: 0x4DA2D9, alpha: 0.8)

(0x4DA2D9).color

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()

Latest podspec

{
    "name": "SwiftColor",
    "version": "1.4.0",
    "summary": "Swift Color Extensions",
    "homepage": "https://github.com/icodesign/SwiftColor",
    "license": "MIT",
    "authors": {
        "icodesign": "[email protected]"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/icodesign/SwiftColor.git",
        "tag": "1.4.0"
    },
    "source_files": [
        "SwiftColor",
        "SwiftColor/**/*.{swift}"
    ],
    "requires_arc": true
}

Pin It on Pinterest

Share This