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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM