Union UIBezierPaths rather than apend path

You can get desired result easily by following 2 concepts of Core Graphics :- i)CGBlendMode ii)OverLap2Layer Blend modes tell a context how to apply new content to itself. They determine how pixel data is digitally blended. class UnionUIBezierPaths : UIView { var firstBeizerPath:UIImage! var secondBeizerPath:UIImage! override func draw(_ rect: CGRect) { super.draw(rect) firstBeizerPath = drawOverLapPath(firstBeizerpath: … Read more

How to Animate a UIBezierPath

I am not an expert on CoreAnimation but you can define a CABasicAnimation as follows CABasicAnimation *morph = [CABasicAnimation animationWithKeyPath:@”path”]; morph.duration = 5; morph.toValue = (id) [self getTrianglePath]; [maskLayer addAnimation:morph forKey:nil]; The first line states that you want to define an animation that changes the path property of the layer. The second line states that … Read more

How to crop the image using UIBezierPath?

You can use a shapeLayer for that. Something like, UIBezierPath *aPath = [UIBezierPath bezierPath]; for (NSString *pointString in pointArray) { if ([pointArray indexOfObject:pointString] == 0) [aPath moveToPoint:CGPointFromString(pointString)]; else [aPath addLineToPoint:CGPointFromString(pointString)]; } [aPath closePath]; CAShapeLayer *shapeLayer = [CAShapeLayer layer]; shapeLayer.path = aPath.CGPath; [view.layer setMask:shapeLayer];//or make it as [imageview.layer setMask:shapeLayer]; //and add imageView as subview of whichever … Read more

UIBezierPath: How to add a border around a view with rounded corners?

You can reuse the UIBezierPath path and add a shape layer to the view. Here is an example inside a view controller. class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Create a view with red background for demonstration let v = UIView(frame: CGRectMake(0, 0, 100, 100)) v.center = view.center v.backgroundColor = UIColor.redColor() view.addSubview(v) … 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