Gradient Fill in Swift for iOS-Charts

后端 未结 5 1877
醉梦人生
醉梦人生 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 10:55

    For swift4

    let colorTop =  UIColor(red: 255.0/255.0, green: 149.0/255.0, blue: 0.0/255.0, alpha: 1.0).cgColor
    let colorBottom = UIColor(red: 255.0/255.0, green: 94.0/255.0, blue: 58.0/255.0, alpha: 1.0).cgColor
    
    let gradientColors = [colorTop, colorBottom] as CFArray
    let colorLocations:[CGFloat] = [0.0, 1.0]
    let gradient = CGGradient.init(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: gradientColors, locations: colorLocations) // Gradient Object
    yourDataSetName.fill = Fill.fillWithLinearGradient(gradient!, angle: 90.0)
    

提交回复
热议问题