本文介绍了如何修改UIColor的色调,亮度和饱和度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我说我有一个UIColor

  UIColor * color = [UIColor redColor]; 

现在我想修改饱和度/色调/亮度,我该怎么做?
我确实阅读了文档,但我仍然很困惑



我想修改我制作的UIColor([UIColor redColor])不会启动新颜色有一些偏好。如何修改它保留原件。我知道 colorWithHue:saturation:brightness:alpha:方法,我需要更新现有颜色的属性,保持红色。

解决方案

您可以在颜色上调用 getHue:saturation:brightness:alpha:,然后调整值,然后使用 + [UIColor colorWithHue:saturation:brightness:alpha:]



<$ p,使用调整后的组件创建新颜色$ p> CGFloat色调,饱和度,亮度,alpha;
BOOL ok = [< color> getHue:& hue saturation:& saturation brightness:& brightness alpha:& alpha];
如果(!ok){
//处理错误
}
// ...调整组件..

UIColor * newColor = [UIColor colorWithHue:色调饱和度:饱和度亮度:亮度alpha:alpha];


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.

解决方案

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 ] ;

这篇关于如何修改UIColor的色调,亮度和饱和度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 00:40