码迷,mamicode.com
首页 > 其他好文 > 详细

绘制虚线

时间:2015-12-19 13:46:31      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

  UIImageView *dottedLineView = [[UIImageView alloc]initWithFrame:CGRectMake(25, 130, GetWindowsFrameWidth - 50, 2)];
    [self addSubview:dottedLineView];
    
    UIGraphicsBeginImageContext(dottedLineView.frame.size);   //开始画线
    [dottedLineView.image drawInRect:CGRectMake(0, 0, dottedLineView.frame.size.width, dottedLineView.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);  //设置线条终点形状
    
    CGFloat lengths[] = {3,3};
    CGContextRef line = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(line, [UIColor grayColor].CGColor);
    
    CGContextSetLineDash(line, 0, lengths, 2);  //画虚线
    CGContextMoveToPoint(line, 0.0, 2.0);    //开始画线
    CGContextAddLineToPoint(line, GetWindowsFrameWidth - 48, 2.0);
    CGContextStrokePath(line);
    
    dottedLineView.image = UIGraphicsGetImageFromCurrentImageContext();

 

绘制虚线

标签:

原文地址:http://www.cnblogs.com/10-19-92/p/5058995.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!