Latest 1.0.0
Homepage https://github.com/icodesign/SwiftColor
License MIT
Platforms ios 8.0, requires ARC
Authors

A Swift Extension for UIColor supporting iOS and Mac.

Installation

Embedded frameworks require a minimum deployment target of iOS 8.

CocoaPods

Add pod 'SwiftColor' to your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'SwiftColor'

Carthage

To integrate SwiftColor into your Xcode project using Carthage, specify it in your Cartfile:

github "icodesign/SwiftColor"

Manually

You can also integrate SwiftColor directly with souce code. Clone the repo and copy SwiftColor.swift to your project.

Usage

Color Init

SwiftColor provides a typealias for UIColor/NSColor as Color.

Initialize with Hex String

Color("000")
Color("000C")
Color("0x4DA2D9")
Color(hexString: "#4DA2D9")
Color(hexString: "#4DA2D9CC")

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

"#4DA2D9CC".color

Initialize with Hex Int

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 to image

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

Latest podspec

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

Pin It on Pinterest

Share This