// 画虚线
// 创建一个imageView 高度是你想要的虚线的高度 一般设为2
UIImageView *_lineImg;
_lineImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, mibg.heightL/2 , mibg.widthL -20, 2)];
// +upbg.heightL
// 调用方法 返回的iamge就是虚线
_lineImg.image = [self drawLineByImageView:_lineImg];
// 添加到控制器的view上
// 返回虚线image的方法
- (UIImage *)drawLineByImageView:(UIImageView *)imageView{
UIGraphicsBeginImageContext(imageView.frame.size); //开始画线 划线的frame
[imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];
//设置线条终点形状
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
// 5是每个虚线的长度 1是高度
CGFloat lengths[] = {5,1};
CGContextRef line = UIGraphicsGetCurrentContext();
// 设置颜色
CGContextSetStrokeColorWithColor(line, [UIColor colorWithWhite:0.408 alpha:1.000].CGColor);
CGContextSetLineDash(line, 0, lengths, 2); //画虚线
CGContextMoveToPoint(line, 0.0, 2.0); //开始画线
CGContextAddLineToPoint(line, SCREENWIDTH-15-6, 2.0);
CGContextStrokePath(line);
// UIGraphicsGetImageFromCurrentImageContext()返回的就是image
return UIGraphicsGetImageFromCurrentImageContext();
}
iOS绘制虚线
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 画虚线需要用到的函数:CG_EXTERN void CGContextSetLineDash(CGContextR...