1
私は、1つの文脈で破線と実線を描きたい。しかし、最初に破線を描くと、2番目の線も破線です。どのようにcontext.setLineDash
をクリーンアップするのですか?私はcontext.beginContext()
を試しましたが、それは役に立ちません。実線と破線を1つの文脈で描く
if let context = UIGraphicsGetCurrentContext() {
// The first line
let startPoint = CGPoint(x: 20, y: rect.height/2)
let endPoint = CGPoint(x: rect.width - 40, y: rect.height/2)
context.move(to: startPoint)
context.addLine(to: endPoint)
context.setLineWidth(1)
context.setLineDash(phase: 0, lengths: [4, 4])
context.setStrokeColor(UIColor.progressDashLineColor.cgColor)
context.strokePath()
// Second line
let startPoint1 = CGPoint(x: 20, y: rect.height/2 + 5)
let endPoint1 = CGPoint(x: rect.width-120, y: rect.height/2)
context.setStrokeColor(UIColor.mainColor.cgColor)
context.setLineWidth(5)
context.move(to: startPoint1)
context.addLine(to: endPoint1)
context.setLineCap(.round)
context.strokePath()
}