在iOS中,如何使用滑块的渐变背景颜色绘制滑块旋钮的背景颜色?

时间:2016-05-05 09:21:21

标签: ios objective-c slider gradient

enter image description here

现在我们有一个圆形滑块,其背景颜色为渐变(混合了十六进制颜色值" 00DBDB"和" FFC800"),我已经绘制了圆形滑块,问题我是如何改变旋钮颜色以使其背景颜色与其在不同滑块上的颜色几乎相同的?我也搜索了谷歌,但没有得到任何有用的信息。任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

感谢功能强大的StackOverflow及其专业用户,我在Find color at point between two colorsCalculate the color at a given point on a gradient between two colors找到了问题的答案

完整的代码是:

@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