Skip to content

Instantly share code, notes, and snippets.

@klein-artur
Last active May 29, 2022 21:10
Show Gist options
  • Save klein-artur/025a0fa4f167a648d9ea to your computer and use it in GitHub Desktop.
Save klein-artur/025a0fa4f167a648d9ea to your computer and use it in GitHub Desktop.
get complementary color to UIColor in Swift
// 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