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();

 

posted on 2015-12-19 13:12  怡情_老二  阅读(196)  评论(0)    收藏  举报