How can I combine uibezierpath drawings?

I am trying to combine several UIBezierPath drawings; I have different types of drawings that I can make (row, cubic bezier, quadratic bezier), and each of them can be filled or unfilled. I choose the type of pattern randomly, and my goal is to make 3 different patterns that are connected at a point; therefore, when the first, say, linear drawings end, the second path can be a cubic bezier; where it ends, the third may be a completed line drawing begins. I have a UIView square that I am trying to draw; and each path should have its own part of the UIView - the first 1/3, second and third. Can I create this with one UIBezierPath object, or do I need to create 3 different ones? How to get them to finish work and start in one place? is there any way to do this using subfolders?

+4
source share
3 answers

UIBezierPath has its own instance methods such as ( DOC )

  • -addLineToPoint:
  • -addArcWithCenter:radius:startAngle:endAngle:clockwise:
  • -addCurveToPoint:controlPoint1:controlPoint2:
  • -addQuadCurveToPoint:controlPoint:
  • -appendPath:

You can combine the paths one by one. When you do, use -closePath to close the path.

Feel free to take a look at my open lib library called UIBezierPath-Symbol .;)


And if you want to customize your drawing more, I recommend CGMutablePath . You can create each path as complex as you want (you can combine simple paths using the CGPathAdd... methods CGPathAdd... ). Finally, use CGPathAddPath() to combine them.

 void CGPathAddPath ( CGMutablePathRef path1, // The mutable path to change. const CGAffineTransform *m, // A pointer to an affine transformation matrix, or NULL if no transformation is needed. If > specified, Quartz applies the transformation to path2 before it is added to path1. CGPathRef path2 // The path to add. ); 
+8
source

You can combine the paths as follows:

 UIBezierPath *endPath = [UIBezierPath bezierPath]; [endPath appendPath:leftLine]; [endPath appendPath:rightLine]; [endPath appendPath:midLine]; 

enter image description here

+2
source

A UIBezierPath is just a shell for CGPath, which in itself is just a set of instructions for drawing (by stroke or filling, or both). This drawing can take place anywhere. In other words, UIBezierPath is just a drawing tool; The drawing itself is important. Given the graphics context (which can be UIView, UIImage, CALayer, etc.), you can make as many drawings as you want, for example, a line, then cubic bezier, then a filled line drawing. But how you execute these drawing bits is completely up to you. You don’t have to worry if you are doing this with three UIBezierPaths, one UIBezierPath, several ways, one way, subpaths, independently (or even copying other pictures into it) - the final effect is all that matters, that is, the accumulated picture in ultimately in this graphic context.

Your question is how to ask: "Should I draw this circle with my right hand or left hand, and should I draw it counterclockwise or clockwise?" It does not matter. Once this is done, what will be drawn is a circle; that's what matters.

+1
source

Source: https://habr.com/ru/post/1480196/


All Articles