Created
May 21, 2015 12:42
-
-
Save berikv/ecf1f79c5bc9921c47ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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)) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dude you can find this code in ui programing book, just use it!