Created
May 14, 2018 13:25
-
-
Save lfarah/b061c1603240b82b4ed1f3ef48c616e2 to your computer and use it in GitHub Desktop.
This file contains 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
extension UIColor { | |
func lighter(by percentage:CGFloat=30.0) -> UIColor? { | |
return self.adjust(by: abs(percentage) ) | |
} | |
func darker(by percentage:CGFloat=30.0) -> UIColor? { | |
return self.adjust(by: -1 * abs(percentage) ) | |
} | |
func adjust(by percentage:CGFloat=30.0) -> UIColor? { | |
var r:CGFloat=0, g:CGFloat=0, b:CGFloat=0, a:CGFloat=0; | |
if(self.getRed(&r, green: &g, blue: &b, alpha: &a)){ | |
return UIColor(red: min(r + percentage/100, 1.0), | |
green: min(g + percentage/100, 1.0), | |
blue: min(b + percentage/100, 1.0), | |
alpha: a) | |
}else{ | |
return nil | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment