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 ?
Related
I'm building an app with some UIBezierPath instances and I want to position a circle at the beginning of two of them. In the image, it's where the arrows are pointing.
How can I achieve that assuming I have the reference to both UIBezierPath instances?
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.
I'm drawing chart and i want to add buttons on calayers.This red and blue color shapes are CAShaperlayer. i have used uibezier path to draw those layers.
Below is one of the good library to solve your problem.
You can download the source code from here.
Check into appetize.io
How to draw a dynamic circle in Objective-C
I have to draw 2 circles first outer circle radius is fixed shown in figure filled with green Color (A).
The other circle is dynamic based on some radius(B).
How can I achieve this.
Subclass an UIView and then override its drawRect method. Inside it use some NSBezierPaths and NSColor settings to make your drawings.
drawRect:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instm/UIView/drawRect:
Cocoa drawings
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40003290-CH201-SW1
Bezier paths
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Paths/Paths.html
Colors
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Color/Color.html#//apple_ref/doc/uid/TP40003290-CH205-BAJDFIFE
This might help you,
Download sketch from apple. http://developer.apple.com/library/mac/#samplecode/Sketch
see more
stackoverflow link
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