渐变填写Swift for iOS-Charts [英] Gradient Fill in Swift for iOS-Charts

查看:824
本文介绍了渐变填写Swift for iOS-Charts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个漂亮的渐变填充,如ios-charts页面上的演示中所示。但是,我无法在swift vs obj-c中解决这个问题。
这是obj-c代码:

I am trying to create a nice gradient fill as seen in the demos on the ios-charts page. However, I cannot figure this out in swift vs obj-c. Here is the obj-c code:

NSArray *gradientColors = @[
                    (id)[ChartColorTemplates colorFromString:@"#00ff0000"].CGColor,
                    (id)[ChartColorTemplates colorFromString:@"#ffff0000"].CGColor
                    ];
CGGradientRef gradient = CGGradientCreateWithColors(nil, (CFArrayRef)gradientColors, nil);

set1.fillAlpha = 1.f;
set1.fill = [ChartFill fillWithLinearGradient:gradient angle:90.f];

现在这是我在swift中的版本:

Now here is my version of that in swift:

    let gradColors = [UIColor.cyanColor().CGColor, UIColor.init(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)]
    let colorLocations:[CGFloat] = [0.0, 1.0]
    let gradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), gradColors, colorLocations)

我缺少的是:
图表填充fillWithLinearGradient

What I am missing is the : Chart Fill fillWithLinearGradient

我无法在任何地方找到fillWithLinearGradient,所以我我有点困惑。

I can't find the fillWithLinearGradient in the pod anywhere so I am a bit confused.

提前感谢您的帮助!
Rob

Thanks in advance for any help! Rob

推荐答案

完美无缺(Swift 3.1和ios-charts 3.0.1)

let gradientColors = [UIColor.cyan.cgColor, UIColor.clear.cgColor] as CFArray // Colors of the gradient
let colorLocations:[CGFloat] = [1.0, 0.0] // Positioning of the gradient
let gradient = CGGradient.init(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: gradientColors, locations: colorLocations) // Gradient Object
yourDataSetName.fill = Fill.fillWithLinearGradient(gradient!, angle: 90.0) // Set the Gradient
set.drawFilledEnabled = true // Draw the Gradient

结果

这篇关于渐变填写Swift for iOS-Charts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆