ios虚线的画法

来源:互联网 发布:王家卫一代宗师 知乎 编辑:程序博客网 时间:2024/04/27 04:21

ios虚线的画法

by 伍雪颖

- (void)drawLine {    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(40, 45, 240, 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);  //设置线条终点形状    CGFloat lengths[] = {1,1};    CGContextRef line = UIGraphicsGetCurrentContext();    CGContextSetStrokeColorWithColor(line, [UIColor whiteColor].CGColor);    CGContextSetLineDash(line, 0, lengths, 2);  //画虚线    CGContextMoveToPoint(line, 0.0, 20.0);    //开始画线    CGContextAddLineToPoint(line, 310.0, 20.0);    CGContextStrokePath(line);    imageView1.image = UIGraphicsGetImageFromCurrentImageContext();}

0 0
原创粉丝点击