码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 绘图(虚线、椭圆)

时间:2014-11-13 12:35:30      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:io   color   os   sp   on   bs   ad   ef   line   

#pragma  画虚线 

  UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 640)];

    imageView1.backgroundColor = [UIColor redColor];

    [self.view addSubview:imageView1];

 

    UIGraphicsBeginImageContext(imageView1.frame.size);   //开始画线

    CGFloat lengths[] = {10,4};  //10个点,空4个点

    CGContextRef line = UIGraphicsGetCurrentContext(); //设置上下文

    CGContextSetStrokeColorWithColor(line, [UIColor blackColor].CGColor);

    

    CGContextSetLineDash(line, 0, lengths, 2);  //画虚线

    CGContextMoveToPoint(line, 100.0, 10.0);    //开始画线,设置X,Y的起点位置

    CGContextAddLineToPoint(line, 300.0,550.0); //线终点的X,Y位置

    CGContextStrokePath(line); //填充

    

    imageView1.image = UIGraphicsGetImageFromCurrentImageContext();

 

 

#pragma 画椭圆

    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 640)];

    [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[] = {10,10};

    CGContextRef ellipse = UIGraphicsGetCurrentContext();

    CGContextSetStrokeColorWithColor(ellipse, [UIColor redColor].CGColor);

    CGContextSetLineDash(ellipse, 0, lengths, 2);  //画虚线园

    CGRect rectangle = CGRectMake(0,0,200,80);

    CGContextAddEllipseInRect(ellipse,rectangle);

    CGContextStrokePath(ellipse);

    imageView1.image = UIGraphicsGetImageFromCurrentImageContext();

 

iOS 绘图(虚线、椭圆)

标签:io   color   os   sp   on   bs   ad   ef   line   

原文地址:http://www.cnblogs.com/i0ject/p/4094507.html

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