Lets say I have a UIColor
UIColor *color = [UIColor redColor];
Now I want to modify the saturation/hue/brigthness, how do I do that? I did read the documentation but i'm still really confused
I want to modify the UIColor I made ([UIColor redColor]) not initiate a new color with some preferences. How do I modify it retaining the original. I do know about thecolorWithHue:saturation:brightness:alpha:
method, I need to update an existing color's properties, keeping the red color.
Photoshop's Hue/Saturation tool is designed to work with 8-bit images. When you try to use the tool on an image that is not 8-bit, you will see an error message. The fix for this is to open your image in Photoshop and go to Image > Mode and make sure that your image is in 8-bit mode.
You can call getHue:saturation:brightness:alpha:
on your color, then adjust the values, then create a new color with your adjusted components using +[UIColor colorWithHue:saturation:brightness:alpha:]
CGFloat hue, saturation, brightness, alpha ;
BOOL ok = [ <color> getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha ] ;
if ( !ok ) {
// handle error
}
// ... adjust components..
UIColor * newColor = [ UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:alpha ] ;
Here is swift UIColor
extension you might find useful:
extension UIColor {
func modified(withAdditionalHue hue: CGFloat, additionalSaturation: CGFloat, additionalBrightness: CGFloat) -> UIColor {
var currentHue: CGFloat = 0.0
var currentSaturation: CGFloat = 0.0
var currentBrigthness: CGFloat = 0.0
var currentAlpha: CGFloat = 0.0
if self.getHue(¤tHue, saturation: ¤tSaturation, brightness: ¤tBrigthness, alpha: ¤tAlpha){
return UIColor(hue: currentHue + hue,
saturation: currentSaturation + additionalSaturation,
brightness: currentBrigthness + additionalBrightness,
alpha: currentAlpha)
} else {
return self
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With