Skip to content

Instantly share code, notes, and snippets.

@ericjkunz
Created April 9, 2019 18:17
Show Gist options
  • Select an option

  • Save ericjkunz/bb3d61cdaaa8e528bde8969f4d0abdc5 to your computer and use it in GitHub Desktop.

Select an option

Save ericjkunz/bb3d61cdaaa8e528bde8969f4d0abdc5 to your computer and use it in GitHub Desktop.
import UIKit
extension UIColor {
func withBrightnessComponent(_ brightness: CGFloat) -> UIColor {
var h: CGFloat = 0
var s: CGFloat = 0
var a: CGFloat = 0
getHue(&h, saturation: &s, brightness: nil, alpha: &a)
return UIColor(hue: h, saturation: s, brightness: brightness, alpha: a)
}
func multiplyingBrightness(by factor: CGFloat) -> UIColor {
var h: CGFloat = 0
var s: CGFloat = 0
var b: CGFloat = 0
var a: CGFloat = 0
getHue(&h, saturation: &s, brightness: &b, alpha: &a)
return UIColor(hue: h, saturation: s, brightness: b * factor, alpha: a)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment