【发布时间】:2018-09-18 00:19:06
【问题描述】:
您好,我正在尝试在 drawRect 中创建图表。目前图表如下所示:
如您所见,“今天”文本被渐变蒙版截断。我像这样创建面具:
// Gradient Fill
let context = UIGraphicsGetCurrentContext()!
let colors = [gradStartColor.cgColor, gradEndColor.cgColor] as CFArray
let colorSpace = CGColorSpaceCreateDeviceRGB()
let colorLocations: [CGFloat] = [0.0, 1.0]
let gradient = CGGradient(colorsSpace: colorSpace, colors: colors, locations: colorLocations)!
let startPoint: CGPoint = CGPoint(x: 0, y: maxY(rect: rect))
let endPoint: CGPoint = CGPoint(x: 0, y: height)
let clippingPath: UIBezierPath = linePath.copy() as! UIBezierPath
clippingPath.addLine(to: CGPoint(x: coords[coords.count - 1].x, y: height))
clippingPath.addLine(to: CGPoint(x: coords[0].x, y: height))
clippingPath.close()
clippingPath.addClip()
context.drawLinearGradient(gradient, start: startPoint, end: endPoint, options: [])
我的问题是如何在图表顶部绘制项目,同时忽略蒙版,以免它们被截断?
【问题讨论】: