Skip to content

Instantly share code, notes, and snippets.

@berikv
Created May 21, 2015 12:42
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berikv/ecf1f79c5bc9921c47ef to your computer and use it in GitHub Desktop.
Save berikv/ecf1f79c5bc9921c47ef to your computer and use it in GitHub Desktop.
//
// UIColor+hex.swift
//
// Created by Berik Visschers on 05-21.
// Copyright (c) 2015 Berik Visschers. All rights reserved.
//
import UIKit
extension UIColor {
// Usage: UIColor(hex: 0xFC0ACE)
convenience init(hex: Int) {
self.init(hex: hex, alpha: 1)
}
// Usage: UIColor(hex: 0xFC0ACE, alpha: 0.25)
convenience init(hex: Int, alpha: Double) {
self.init(
red: CGFloat((hex >> 16) & 0xff) / 255,
green: CGFloat((hex >> 8) & 0xff) / 255,
blue: CGFloat(hex & 0xff) / 255,
alpha: CGFloat(alpha))
}
}
@eonist
Copy link

eonist commented Dec 12, 2015

Dude you can find this code in ui programing book, just use it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment