gpt4 book ai didi

ios - 基于进度值的 UIColor 过渡

转载 作者:IT王子 更新时间:2023-10-29 08:01:54 25 4
gpt4 key购买 nike

我有一个 ProgressBar,我想为其分配一个 customColor 颜色,并根据进度淡入另一种颜色。使用下面的方法我得到了深色彩虹效果颜色,包括红色、深棕色和深绿色。起始颜色为浅蓝色,目标颜色为浅绿色。

-(UIColor *) makeCustomColorFromProgressValue:(float) progress{


UIColor *color;

// startColor Color - lightBlue
float red = 0.53;
float green = 0.82;
float blue = 1;

//Destination Color - lightGreen
float finalRed = 0.53;
float finalGreen = 1;
float finalBlue = 0.82;

float newRed = 80;//finalRed *255;
float newGreen = (finalGreen *progress) *255;
float newBlue = (finalBlue *progress) *255;
color = Rgb2UIColor(newRed, newGreen, newBlue);



return color;
}

最佳答案

您可以在颜色之间进行“线性插值”:

CGFloat newRed   = (1.0 - progress) * red   + progress * finalRed;
CGFloat newGreen = (1.0 - progress) * green + progress * finalGreen;
CGFloat newBlue = (1.0 - progress) * blue + progress * finalBlue;
UIColor *color = [UIColor colorWithRed:newRed green:newGreen blue:newBlue alpha:1.0];

这给出了 progress == 0 的初始颜色和进度 == 1

关于ios - 基于进度值的 UIColor 过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22868182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com