Skip to content

Instantly share code, notes, and snippets.

@neilco
Created October 29, 2015 23:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilco/80d89b90703608487f67 to your computer and use it in GitHub Desktop.
Save neilco/80d89b90703608487f67 to your computer and use it in GitHub Desktop.
Adjust brightness of a UIColor instance
import UIKit
public extension UIColor {
public func colorWithBrightness(brightness: CGFloat) -> UIColor {
var H: CGFloat = 0, S: CGFloat = 0, B: CGFloat = 0, A: CGFloat = 0
if getHue(&H, saturation: &S, brightness: &B, alpha: &A) {
B += (brightness - 1.0)
B = max(min(B, 1.0), 0.0)
return UIColor(hue: H, saturation: S, brightness: B, alpha: A)
}
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment