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

iOS 使用drawRect: 绘制虚线椭圆,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。