Skip to content

Instantly share code, notes, and snippets.

@nicolas-miari
Last active May 22, 2017 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolas-miari/ee40e138d6188a741269 to your computer and use it in GitHub Desktop.
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])
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