iOS 使用drawRect: 绘制虚线椭圆

iOS 使用drawRect: 绘制虚线椭圆

1:首先如果要使用 drawRect 绘图

    要导入 CoreGraphics.framework 框架

    然后 创建 自定义view, 即是 myView继承 UIView;

2: 重写

  

- (void)drawRect:(CGRect)rect

方法;

3:添加如下代码

- (void)drawRect:(CGRect)rect
{

    

    CGContextRef context = UIGraphicsGetCurrentContext();


    CGFloat lengths[] = {5,5,5,5};
    
    
     CGRect aRect= CGRectMake(60, 1,self.bounds.size.width-60*2,self.bounds.size.height-4);
     CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
     CGContextSetLineDash(context, 0, lengths, 4);
     CGContextSetLineWidth(context, 3.0);
     CGContextAddEllipseInRect(context, aRect); //椭圆
     CGContextDrawPath(context, kCGPathStroke);
    
    



    
}

 主要函数

CGContextSetRGBStrokeColor(context, r, g, b, 1.0); 设置图形线的颜色;

CGContextSetLineDash(context, 0, lengths, 4); 设置线条为 虚线;

 CGContextSetLineWidth(context, 3.0);      //设置线宽;

 CGContextAddEllipseInRect(context, aRect); //画椭圆

 CGContextDrawPath(context, kCGPathStroke); 

 

 

参考:http://blog.csdn.net/zhangao0086/article/details/7234859

http://blog.csdn.net/zhibudefeng/article/details/8463268

posted @ 2014-07-24 14:14  cocoajin  阅读(3003)  评论(0编辑  收藏  举报