Gradient Fill in Swift for iOS-Charts

后端 未结 5 1878
醉梦人生
醉梦人生 2020-12-15 10:28

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:

5条回答
  •  一生所求
    2020-12-15 11:04

    This works perfectly (Swift 3.1 and 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
    

    Result

提交回复
热议问题