1

enter image description here

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?

Alfy
  • 889
  • 1
  • 7
  • 17

1 Answers1

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

Community
  • 1
  • 1
Alfy
  • 889
  • 1
  • 7
  • 17