I'm developing an iPhone app with 3.1.3 SDK.
I'm trying to draw a triangle with transparent fill an 1px black stroke with this code:
CGContextMoveToPoint(ctx, position.X, position.Y - (size.height / 2));
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);
CGContextSetLineWidth(ctx, 1.0);
CGContextStrokePath(ctx);
CGContextSetFillColorWithColor(ctx, [[UIColor clearColor] CGColor]);
But I get a black filled triangle.
What am I doing wrong?
If you want to draw a path with transparent fill - then you don't need to fill it - just stroke it when draw, so it seems that your CGContextFillPath method is redundant - remove it:
CGContextMoveToPoint(ctx, position.X, position.Y - (size.height / 2));
CGContextAddLineToPoint(ctx, position.X - (size.width / 2), position.Y + (size.height / 2));
CGContextAddLineToPoint(ctx, position.X + (size.width / 2), position.Y + (size.height / 2));
CGContextSetLineWidth(ctx, 1.0);
CGContextStrokePath(ctx);
来源:https://stackoverflow.com/questions/6545548/how-to-draw-a-triangle-with-quartz-2d