Created
November 30, 2017 06:15
-
-
Save hmhmsh/00a0a2fb41651fdfda0d0e3e42e7f371 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
// | |
// Color.swift | |
// | |
// | |
// Usage | |
// UIColor.HexColor.Red | |
// UIColor.RGBColor.Red | |
// | |
import Foundation | |
import UIKit | |
extension UIColor { | |
convenience public init(hex: Int, alpha: CGFloat = 1.0) { | |
let red = CGFloat((hex & 0xFF0000) >> 16) / 255.0 | |
let green = CGFloat((hex & 0xFF00) >> 8) / 255.0 | |
let blue = CGFloat((hex & 0xFF)) / 255.0 | |
self.init(red:red, green:green, blue:blue, alpha:alpha) | |
} | |
// make hex color list | |
public struct HexColor { | |
public static let Red = UIColor(hex: 0xF44336) | |
public static let Blue = UIColor(hex: 0x2196F3) | |
public static let Green = UIColor(hex: 0x4CAF50) | |
// etc... | |
} | |
// make rgb color list | |
public struct RGBColor { | |
public static let Red = UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment