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