uibezierpath
An easy way to draw a circle using CAShapeLayer
An easy way to draw a circle is to create a CAShapeLayer and add a UIBezierPath. objective-c CAShapeLayer *circleLayer = [CAShapeLayer layer]; [circleLayer setPath:[[UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 100, 100)] CGPath]]; swift let circleLayer = CAShapeLayer(); circleLayer.path = UIBezierPath(ovalIn: CGRect(x: 50, y: 50, width: 100, height: 100)).cgPath; After creating the CAShapeLayer we set its path to be … Read more
How to animate a human written stroke using Swift/iOS?
A couple of concepts in the Apple CAShapeLayer (strokeStart and strokeEnd) really don’t seem to operate as expected when animated. But surely animating the strokeEnd is exactly what you want to do. Use multiple CAShapeLayers over top of one another, each one representing one stroke of the pen to form the desired character shape.
Draw a line with UIBezierPath
Ended up doing it this way: func drawLineFromPoint(start : CGPoint, toPoint end:CGPoint, ofColor lineColor: UIColor, inView view:UIView) { //design the path let path = UIBezierPath() path.move(to: start) path.addLine(to: end) //design path in layer let shapeLayer = CAShapeLayer() shapeLayer.path = path.cgPath shapeLayer.strokeColor = lineColor.CGColor shapeLayer.lineWidth = 1.0 view.layer.addSublayer(shapeLayer) }
How to get a list of points from a UIBezierPath?
You might try this: UIBezierPath *yourPath; // Assume this has some points in it CGPath yourCGPath = yourPath.CGPath; NSMutableArray *bezierPoints = [NSMutableArray array]; CGPathApply(yourCGPath, bezierPoints, MyCGPathApplierFunc); The path applier function will be handed each of the path’s path elements in turn. Check out CGPathApplierFunction and CGPathApply. The path applier function might look something like this … Read more
How to draw a “speech bubble” on an iPhone?
I’ve actually drawn this exact shape before (rounded rectangle with a pointing triangle at the bottom). The Quartz drawing code that I used is as follows: CGRect currentFrame = self.bounds; CGContextSetLineJoin(context, kCGLineJoinRound); CGContextSetLineWidth(context, strokeWidth); CGContextSetStrokeColorWithColor(context, [MyPopupLayer popupBorderColor]); CGContextSetFillColorWithColor(context, [MyPopupLayer popupBackgroundColor]); // Draw and fill the bubble CGContextBeginPath(context); CGContextMoveToPoint(context, borderRadius + strokeWidth + 0.5f, strokeWidth + … Read more
UIBezierPath Subtract Path
Actually there is a much simpler way for most cases, example in Swift: path.append(cutout.reversing()) This works because the default fill rule is the non-zero winding rule.
Drawing UIBezierPath on code generated UIView
It wasn’t long ago that I didn’t even know how to pronounce Bézier, let alone know how to use Bézier paths to make a custom shape. The following is what I have learned. It turns out that they aren’t as scary as they seem at first. How to draw a Bézier path in a custom … Read more