Now we have a circular slider whose background color is gradient (mixed with hex color value of "00DBDB" and "FFC800"), I have already drawn the circular slider, the problem is how shoud I do to change the knob color to make its background color nearly same with its color at different slider's point? I have also searched google but got nothing useful information. Any one can help?
Asked
Active
Viewed 1,075 times
1
-
Any chance your slider is or can be open sourced? – user1366911 Oct 04 '18 at 21:59
1 Answers
0
Thanks the powerful StackOverflow and its professional users, I found the answer to the question at Find color at point between two colors and Calculate the color at a given point on a gradient between two colors
The complete code is :
@implementation UIColor (Percentage)
+ (UIColor *)colorFromStartColor:(UIColor *)startColor endColor:(UIColor *)endColor ofPercentage:(CGFloat)percentage {
UIColor *resultColor;
percentage = MAX(0.0, MIN(percentage, 1.0));
CGFloat startRed, startBlue, startGreen, startAlpha;
CGFloat endRed, endBlue, endGreen, endAlpha;
[startColor getRed:&startRed green:&startGreen blue:&startBlue alpha:&startAlpha];
[endColor getRed:&endRed green:&endGreen blue:&endBlue alpha:&endAlpha];
CGFloat resultRed, resultBlue, resultGreen;
resultRed = startRed + percentage * (endRed - startRed);
resultGreen = startGreen + percentage * (endGreen - startGreen);
resultBlue = startBlue + percentage * (endBlue - startBlue);
resultColor = [UIColor colorWithRed:resultRed green:resultGreen blue:resultBlue alpha:1.0];
return resultColor;
}
@end