Created
October 29, 2015 23:20
-
-
Save neilco/80d89b90703608487f67 to your computer and use it in GitHub Desktop.
Adjust brightness of a UIColor instance
This file contains hidden or 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
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