Last active
May 22, 2017 07:52
-
-
Save nicolas-miari/ee40e138d6188a741269 to your computer and use it in GitHub Desktop.
Create a UIColor instance with `RGBA` values in the integer range [0, 255] (instead of float [0.0, 1.0])
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
import UIKit | |
extension UIColor { | |
convenience init( | |
redByte red: UInt8, | |
greenByte green: UInt8, | |
blueByte blue: UInt8, | |
alphaByte alpha: UInt8 | |
) { | |
self.init( | |
red: CGFloat(red)/255.0, | |
green: CGFloat(green)/255.0, | |
blue: CGFloat(blue)/255.0, | |
alpha: CGFloat(alpha)/255.0 | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment