如何用QUARTZ 2D绘制一个三角形? [英] How to draw a triangle with QUARTZ 2D?

查看:131
本文介绍了如何用QUARTZ 2D绘制一个三角形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用3.1.3 SDK开发一个iPhone应用程序。

I'm developing an iPhone app with 3.1.3 SDK.

我试图画一个带有透明填充1px黑色笔触的三角形,

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.

我做错了什么?

推荐答案

如果你想画一个透明填充的路径 - 填充它 - 只是在绘制时敲击,所以看起来你的CGContextFillPath方法是多余的 - 删除它:

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);

这篇关于如何用QUARTZ 2D绘制一个三角形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆