uibezierpath subtract path to draw patial rectangle - ios

I want to use uibezierpath to draw sth like the followling pic.But I only find some api add whole rect ,can I use some tricks to draw patial rect

Related

Is there a UIBezierPath equivalent of CGPath's `addArc(tangent1End:tangent2End:radius:transform:)`?

Constructing custom variations of rounded rectangles is fussy business. The Swift V 5.1 answer in this thread:
Swift: UIBezierPath Stroke Animation from Center
Describes out to draw a rounded rectangle starting from the top center, so you can animate stroking it starting from that point.
It uses the UIBezierPath method addArc(withCenter:radius:startAngle:endAngle:clockwise:) to draw the corner arcs of the rounded rectangle.
Getting the code right to draw the connected series of line segments and quarter arcs requires quite a bit of care, plus some knowledge of trig to figure out the angles of the different arcs for each quadrant.
CGPath has a variation on addArc, addArc(tangent1End:tangent2End:radius:transform:), that works differently. It takes "tangent end" points that define the arc in a way that's less fussy to set up (once you figure out how it works.)
I can't find an equivalent method for UIBezierPath. Am I missing something? I guess the answer is to create a CGPath (or rather, CGMutablePath using calls to addArc(tangent1End:tangent2End:radius:transform:) and then use the UIBezierPath initializer that takes a CGPath, but that is an added step that makes the code a little bit more confusing.
It looks like there is no UIBezierPath equivalent to the CGPath method addArc(tangent1End:tangent2End:radius:transform:).
I guess the answer is to just use CGPath when you want to add arcs in the form addArc(tangent1End:tangent2End:radius:transform:), and then convert the result to a UIBezierPath using the UIBezierPath.init(cgPath:) initializer.
At first I was thinking I could write an extension of UIBezierPath that would add a addArc(tangent1End:tangent2End:radius:transform:) method to UIBezierPath, but that would get very messy, since addArc(tangent1End:tangent2End:radius:transform:) uses the current pen position in the active path to figure out the first tangent line.

UIBezierPath with random shaped border in Swift

I am drawing a UIBezierPath on a CGContext using Swift 3.0. I need the path to have random shaped border, i.e. outline - like the blue path in this image:
I haven't found anything in UIBezierPath that can help to do that. Could this be done using CGPattern or even CGPath ?

Circle Progress View like activity app

I am trying to create an animated radial chart that looks like the activity app created by Apple. I provide an image to show what I would like as result:
Do you know how to obtain this result? If you have any idea could you please focus on the following points?
Create the gradient inside each circle
Create the shadow on the head of the circle
Thank you very much in advance.
Check out my custom control, I tried to make it as close as possible to the Activity app design, and everything is customizable.
https://github.com/maxkonovalov/MKRingProgressView
The basic idea behind the algorithm is quite simple.
To draw arc line with changing color:
Generate a conical gradient image
You can use a prerendered image from Photoshop or generate your own dynamically. I use a gradient image generator from here: https://github.com/maxkonovalov/MKGradientView.
Clip gradient image to show only the arc
CGContextSaveGState(ctx)
CGContextAddPath(ctx, arcPath)
CGContextClip(ctx)
CGContextDrawImage(ctx, gradientRect, gradientImage)
CGContextRestoreGState(ctx)
Drawing the shadow is even simpler:
Draw shadow behind your progress arc (shown with 50% opacity here)
I draw a circle shape matching arc's end for the shadow.
CGContextSetShadow(ctx, offset, shadowRadius)
CGContextAddPath(ctx, shadowPath)
CGContextSetFillColorWithColor(ctx, shadowColor)
CGContextFillPath(ctx)
Clip the shadow to fit into the progress circle
CGContextSaveGState(ctx)
CGContextAddPath(ctx, circlePath)
CGContextClip(ctx)
// Draw shadow...
CGContextRestoreGState(ctx)
And the final result looks like this:
This isn't quite what you need as it appears to generate the image for you, but you could get some good info from the source.
https://github.com/hmaidasani/RadialChartImageGenerator

Delphi draw a closed rectangle with two rounded corners and to rectangular corners

How can I draw a rectangle that has two round corners and the opposite corners are rectangular corners. The shape must be closed so it can be filled with the Brush color. The Polyline method doesn't draw curved lines. Can I add the points of an Arc to the polyline points? I tried to draw a RoundRect using Canvas method and then, overlapping a rectangle over the lower round corners, but I couldn't figure out how to erase the upper line of the rectangle when drawign just the border of the shape without filling it. Note: if you think is relevant, I can add the code I used.
Sample of the desired shape:
Sample of what I got with Delphi:
You don't have to fill the shape at the same time you draw it. You can use a series of TCanvas.LineTo() and TCanvas.ArcTo()/TCanvas.AngleArc() calls first to create the shape, then call TCanvas.FloodFill() afterwards to fill it.
Otherwise, you can overlap TCanvas.Rectangle() on top of TCanvas.RoundRect() with the same fill color, and then use TCanvas.MoveTo()/TCanvas.LineTo() to draw over the dividing line with the same fill color.
Another option would be to forget using TCanvas drawing methods and just use Win32 API calls instead. Use CreateRoundRectRgn(), CreateRectRgn(), and CombineRn() to create a HRGN that has your desired shape, then use FillRgn() and FrameRgn() to draw on your TCanvas using that HRGN.

UIView & Image Clipping in iPhone?

Let said I have a image which the circle in the middle is transparent and I use the drawRect function to draw sqaure like the second image below.
Then what I want to do is to get the alpha layer of the first image, the circle as a path, then apply on the square i draw and clip it and draw like the final image, just want it to draw on the circle path.
Thank in advance.

Resources