iOS 图片编辑——涂鸦——带剪头的线条

该博客介绍了如何在iOS应用中扩展上一节的内容,即在图片上画线段,并在线段末端添加箭头。作者提供了代码示例和下载链接,以便读者实践操作。此外,还分享了苹果开发交流群的信息,鼓励开发者们共同学习。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上节我们讲了 给图片上画线段

上节地址:http://blog.youkuaiyun.com/lwjok2007/article/details/50865598

这节我们在上节的基础上稍微拓展一下,给线段末尾加上一个箭头

我们接着上节代码 下载地址见上节末尾

给DrawLine 类中添的方法 drawRect 中添加一段代码

        //添加剪头
        double r = sqrt((line.end.x-line.begin.x)*(line.end.x-line.begin.x)+(line.begin.y-line.end.y)*(line.begin.y-line.end.y));//线条长度
        CGContextMoveToPoint(cgt,line.end.x,line.end.y);
        //P1
        CGContextAddLineToPoint(cgt,line.end.x-(10*(line.begin.y-line.end.y)/r),line.end.y-(10*(line.end.x-line.begin.x)/r));
        //P3
        CGContextAddLineToPoint(cgt,line.end.x+(20*(line.end.x-line.begin.x)/r), line.end.y-(20*(line.begin.y-line.end.y)/r));
        //P2
        CGContextAddLineToPoint(cgt,line.end.x+(10*(line.begin.y-line.end.y)/r),line.end.y+(10*(line.end.x-line.begin.x)/r));
        
        CGContextAddLineToPoint(cgt, line.end.x,line.end.y);
        CGContextDrawPath(cgt,kCGPathFillStroke);
        CGContextStrokePath(cgt);

以上方法的思路 就是在线段画完之后 确定三个点 画一个三角形作为箭头形状



好了 基本思路就是这样 源代码会上传到群空间


大家有兴趣可以去下载

demo:【60314画线段带箭头AddLine.zip】

苹果开发群 :414319235  欢迎加入,共同学习



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值