【问题标题】:In iOS, how to draw the slider knob's background color chaning with the slider's gradient background color?在 iOS 中,如何绘制随着蜘蛛渐变背景颜色变化的滑块旋钮背景颜色?
【发布时间】:2016-05-05 09:21:21
【问题描述】:

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

【问题讨论】:

  • 您的滑块是否有可能是或可以开源的?

标签: ios objective-c slider gradient


【解决方案1】:

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

完整的代码是:

@implementation UIColor(百分比) + (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

【讨论】:

    猜你喜欢
    • 2017-03-25
    • 1970-01-01
    • 2018-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-21
    • 1970-01-01
    • 2012-03-15
    相关资源
    最近更新 更多