Drawing a bridge with Quartz 2D
-
29-10-2019 - |
Question
I'm trying to draw the following image:
Using this objective-c code:
CGContextSetFillColorWithColor(ctx, [[UIColor redColor] CGColor]);
CGContextMoveToPoint(ctx, position.X - (size.width / 2), position.Y - (size.height / 2));
CGContextAddLineToPoint(ctx, position.X - (size.width / 2), position.Y + (size.height / 2));
CGContextAddLineToPoint(ctx, position.X - (size.width / 4), position.Y + (size.height / 2));
CGContextAddArc(ctx, position.X, position.Y + (size.height / 2), (size.width / 4), -M_PI, M_PI, 0);
CGContextAddLineToPoint(ctx, position.X + (size.width / 2), position.Y + (size.height / 2));
CGContextAddLineToPoint(ctx, position.X + (size.width / 2), position.Y - (size.height / 2));
CGContextFillPath(ctx);
But it doesn't work. I get this image:
The width of the image is size.width and the height is size.height.
The origin is (position.X, position.Y)
. This point is in center, at (size.width /2, size.height / 2).
The first point is the upper left corner, and the second one is the bottom left corner. And then continues to the right.
Here is a better explanation:
Sorry for my English.
Any advice?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow