Skip to content

Instantly share code, notes, and snippets.

dariukas / UIColor+Extension
Last active August 6, 2018 08:47
The extension to return the complement colour or two complement colours of a colour in Swift.
extension UIColor {
convenience init(red: Int, green: Int, blue: Int) {
let newRed = CGFloat(red)/255
let newGreen = CGFloat(green)/255
let newBlue = CGFloat(blue)/255
self.init(red: newRed, green: newGreen, blue: newBlue, alpha: 1.0)
var complement: UIColor {
return self.withHueOffset(0.5)