Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// 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

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.