UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 100, 320, 20)]; [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); //设置线条终点形状 float lengths[] = {10,5}; CGContextRef line = UIGraphicsGetCurrentContext(); CGContextSetStrokeColorWithColor(line, [UIColor redColor].CGColor); CGContextSetLineDash(line, 0, lengths, 2); //画虚线 CGContextMoveToPoint(line, 0.0, 20.0); //开始画线 CGContextAddLineToPoint(line, 310.0, 20.0); CGContextStrokePath(line); imageView1.image = UIGraphicsGetImageFromCurrentImageContext();
iOS 画虚线
最新推荐文章于 2024-05-11 09:28:59 发布
这篇博客介绍了如何在iOS应用中利用Objective-C代码实现UIImageView上虚线的绘制。通过创建UIImageView,开始图形上下文,设置线条样式,包括线帽形状、虚线模式,然后指定颜色和路径,最后完成路径并获取图像。
摘要由CSDN通过智能技术生成