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

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