قالب وردپرس درنا توس
Home / IOS Development / ios – Draw a diagonal line with side curves UIBezierPath

ios – Draw a diagonal line with side curves UIBezierPath



I will draw a diagonal line with side curves like the following
“/>

code:

  func drawCanvas1 (frame: CGRect = CGRect (x: 0, y: 0, width: 240, height: 120)) {

//// Bezier Drawing
la bezierPath = UIBezierPath ()
UIColor.black.setStroke ()
bezierPath.lineWidth = 1
bezierPath.stroke ()


//// Bezier 2 Drawing
la bezier2Path = UIBezierPath ()
bezier2Path.move (to: CGPoint (x: frame.minX + 0.5, y: frame.minY + 103.42))
bezier2Path.addCurve (til: CGPoint (x: frame.minX + 12.17, y: frame.minY + 119.5), controlPoint1: CGPoint (x: frame.minX + 0.5, y: frame.minY + 103.42 ), controlPoint2: CGPoint x: frame.minX + 0.5, y: frame.minY + 119.5))
bezier2Path.addCurve (til: CGPoint (x: frame.minX + 232.03, y: frame.minY + 26.23), controlPoint1
: CGPoint (x: frame.minX + 23.85, y: frame.minY + 119.5), controlPoint2: CGPoint x: frame.minX + 232.03, y: frame.minY + 26.23)) bezier2Path.addCurve (til: CGPoint (x: frame.minX + 237.87, y: frame.minY + 0.5), controlPoint1: CGPoint (x: frame.minX + 232.03, y: frame.minY + 26.23), controlPoint2: CGPoint x: frame.minX + 243.7, y: frame.minY + 16.58)) UIColor.black.setStroke () bezier2Path.lineWidth = 1 bezier2Path.lineCapStyle = .square bezier2Path.stroke () la layer1 = CAShapeLayer () layer1.path = bezierPath.cgPath la layer2 = CAShapeLayer () layer2.path = bezier2Path.cgPath imageCollectionView.layer.addSublayer (layer1) imageCollectionView.layer.addSublayer (lag2) }

output:

  enter picture description here

As you see in production, it fills with black color while I have only given a blow. I'm not very good at the bezier path. can anyone help me get the desired effect


Source link