Last active
May 29, 2022 21:10
-
-
Save klein-artur/025a0fa4f167a648d9ea to your computer and use it in GitHub Desktop.
get complementary color to UIColor in Swift
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
// get a complementary color to this color: | |
func getComplementaryForColor(color: UIColor) -> UIColor { | |
let ciColor = CIColor(color: color) | |
// get the current values and make the difference from white: | |
let compRed: CGFloat = 1.0 - ciColor.red | |
let compGreen: CGFloat = 1.0 - ciColor.green | |
let compBlue: CGFloat = 1.0 - ciColor.blue | |
return UIColor(red: compRed, green: compGreen, blue: compBlue, alpha: 1.0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment