画线 ios

本文介绍如何使用Objective-C在iOS应用中实现自定义虚线的绘制过程。通过设置上下文、线条属性及颜色,利用Core Graphics框架完成指定路径上的虚线绘制,并展示了具体的实现代码。

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

//

float h=0;
UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,h)];
[self.view addSubview:imageView1];

UIGraphicsBeginImageContext(imageView1.frame.size);   //开始画线
[imageView1.image drawInRect:CGRectMake(0, 0, imageView1.frame.size.width, imageView1.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);  //设置线条终点形状
//间隔
CGFloat lengths[] = {4,4};
CGContextRef line = UIGraphicsGetCurrentContext();
//颜色
CGContextSetStrokeColorWithColor(line, RGBA(15, 41, 74, 1).CGColor);

CGContextSetLineDash(line, 0, lengths, 2);  //画虚线

CGContextMoveToPoint(line, 0.0, h);    //开始画横线
CGContextAddLineToPoint(line, SCREEN_WIDTH, h);

// CGContextMoveToPoint(line, SCREEN_WIDTH/2,0); //开始画竖线
// CGContextAddLineToPoint(line, SCREEN_WIDTH/2, h);
CGContextStrokePath(line);
//加载popView;
imageView1.image = UIGraphicsGetImageFromCurrentImageContext();

//

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值