开发者

How to draw a triangle with QUARTZ 2D?

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));
CG开发者_如何转开发ContextAddLineToPoint(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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜