Skip to content

HEX color handling as an extension for UIColor. Written in Swift.

License

Notifications You must be signed in to change notification settings

jmper1/SwiftColors

 
 

Repository files navigation

SwiftColors

Build Status Cocoapods Compatible Carthage Compatible Platform License

HEX color handling as an extension for UIColor. Written in Swift.

Examples

iOS

// With hash
let color: UIColor = UIColor(hexString: "#ff8942")

// Without hash, with alpha
let secondColor: UIColor = UIColor(hexString: "ff8942", alpha: 0.5)

// Short handling
let shortColorWithHex: UIColor = UIColor(hexString: "fff")

For those who don't want to type the double quotation, you can init a color from a real hex value (an Int)

// With hash
let color: UIColor = UIColor(hex: 0xff8942)

// Without hash, with alpha
let secondColor: UIColor = UIColor(hex: 0xff8942, alpha: 0.5)

OSX

// With hash
let color: NSColor = NSColor(hexString: "#ff8942")

// Without hash, with alpha
let secondColor: NSColor = NSColor(hexString: "ff8942", alpha: 0.5)

// Short handling
let shortColorWithHex: NSColor = NSColor(hexString: "fff")

// From a real hex value (an `Int`)
// With hash
let color: NSColor = NSColor(hex: 0xff8942)

// Without hash, with alpha
let secondColor: NSColor = NSColor(hex: 0xff8942, alpha: 0.5)

Installation

CocoaPods

To integrate SwiftColors into your Xcode project using CocoaPods, specify it in your Podfile:

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

pod 'SwiftColors'

Then, run the following command:

$ pod install

And add import SwiftColors to the top of the files using SwiftColors.

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

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

github "thii/SwiftColors"

Run carthage to build the framework and drag the built SwiftColors.framework into your Xcode project.

Manually

  • Drag and drop SwiftColors.swift file into your project

Requirements

iOS 8.0 or above.

License

MIT

About

HEX color handling as an extension for UIColor. Written in Swift.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 92.7%
  • Ruby 5.2%
  • Objective-C 2.1%