Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GradientMaskLineRenderer: LineChartRenderer {
- override init(dataProvider: LineChartDataProvider, animator: Animator, viewPortHandler: ViewPortHandler) {
- super.init(dataProvider: dataProvider, animator: animator, viewPortHandler: viewPortHandler)
- }
- override func drawFilledPath(context: CGContext, path: CGPath, fill: Fill, fillAlpha: CGFloat) {
- let rect = viewPortHandler.contentRect
- let colorSpace = CGColorSpaceCreateDeviceGray()
- let bitmapContext = CGContext(
- data: nil,
- width: Int(rect.size.width),
- height: Int(rect.size.height),
- bitsPerComponent: 8,
- bytesPerRow: Int(rect.size.width),
- space: colorSpace,
- bitmapInfo: CGImageAlphaInfo.none.rawValue
- )!
- let colors = [UIColor.white.cgColor, UIColor.black.cgColor] as CFArray
- let gradient = CGGradient(colorsSpace: colorSpace, colors: colors, locations: nil)!
- bitmapContext.drawLinearGradient(
- gradient,
- start: CGPoint(x: 0, y: 0),
- end: CGPoint(x: 0, y: rect.size.height),
- options: [.drawsAfterEndLocation, .drawsBeforeStartLocation]
- )
- let mask = bitmapContext.makeImage()!
- context.clip(to: rect, mask: mask)
- super.drawFilledPath(context: context, path: path, fill: fill, fillAlpha: fillAlpha)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement