Created
June 13, 2016 20:59
-
-
Save danielt1263/32f101f6e8c7cd8d0085669f682788ca 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
// | |
// UIColorExtensions.swift | |
// | |
// Created by Daniel Tartaglia on 12/4/14. | |
// Copyright (c) 2014 Daniel Tartaglia. MIT License. | |
// | |
import UIKit | |
extension UIColor { | |
convenience init(hex: UInt32) { | |
let red = hex < 0xFFFFFF ? (hex & 0xFF0000) >> 16 : (hex & 0xFF000000) >> 24 | |
let green = hex < 0xFFFFFF ? (hex & 0x00FF00) >> 8 : (hex & 0x00FF0000) >> 16 | |
let blue = hex < 0xFFFFFF ? (hex & 0x0000FF) : (hex & 0x0000FF00) >> 8 | |
let alpha = hex < 0xFFFFFF ? 0xFF : (hex & 0x000000FF) | |
let max: CGFloat = 255 | |
self.init(red: CGFloat(red)/max, green: CGFloat(green)/max, blue: CGFloat(blue)/max, alpha: CGFloat(alpha)/max) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment