Question

I need to draw complex shape, something like this: enter image description here

So I try:

CGFloat offsetAngle = 15 * M_PI/180;

CGPathAddArc(path, nil, 39/2, 30, 39/2-0.1, offsetAngle, -M_PI-offsetAngle, YES);

CGFloat linesXOffset = 2.5;
CGFloat linesYOffset = 30;
CGPathMoveToPoint(path, nil, linesXOffset, linesYOffset);
CGPathAddLineToPoint(path, nil, 39-linesXOffset, linesYOffset);
CGPathAddLineToPoint(path, nil,39/2,//X
                     linesYOffset + CGRectGetHeight(self.bounds)/2-220/2-linesYOffset);

CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setPath:path];

So shape consists of triangle and arc.

But I have the following overlay problem:

enter image description here

Is it possible to fix?

Was it helpful?

Solution

1) Easier:

CGFloat linesYOffset = 35;

2) Another way:

CGFloat offsetAngle = 15 * M_PI/180;
CGMutablePathRef path1 = CGPathCreateMutable();
CGPathAddArc(path1, nil, 39/2, 30, 39/2-0.1, offsetAngle, -M_PI-offsetAngle, YES);

CGMutablePathRef path2 = CGPathCreateMutable();
CGFloat linesXOffset = 5.5;
CGFloat linesYOffset = 30;
CGPathMoveToPoint(path2, nil, linesXOffset, linesYOffset);
CGPathAddLineToPoint(path2, nil, 39-linesXOffset, linesYOffset);
CGPathAddLineToPoint(path2, nil,39/2,//X
                     linesYOffset + 600/2-220/2-linesYOffset);

CAShapeLayer *shapeLayer1 = [CAShapeLayer layer];
[shapeLayer1 setPath:path1];
CAShapeLayer *shapeLayer2 = [CAShapeLayer layer];
[shapeLayer2 setPath:path2];

CAShapeLayer* container = [CAShapeLayer layer];
[container addSublayer:shapeLayer1];
[container addSublayer:shapeLayer2];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top