Skip to content

Instantly share code, notes, and snippets.

@dariukas
dariukas / UIColor+Extension
Last active Aug 6, 2018
The extension to return the complement colour or two complement colours of a colour in Swift.
View UIColor+Extension
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)