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

被折叠的 条评论
为什么被折叠?



