Quartz 2D繪圖

來源:互聯網
上載者:User

標籤:blog   使用   os   width   art   div   

Quartz 2D繪圖只能在UIView中重寫drawRect:方法中進行繪製,其他地方都無效,會報錯。

繪製過程:

1. 擷取上下文 CGContextRef context = UIGraphicsGetCurrentContext();

2. 添加圖形 CGContextAddRect(context , CGRectMake(50, 50, 100, 100));

3. 繪製圖形 CGContextDrawPath(context ,kCGPathEOFill);

4. 關閉上下文 CGContextClosePath(context);

 

Quartz 2D 座標系變換

1. CGContextRotateCTM(CGContextRef c, CGFloat angle)方法可以相對原點旋轉上下文座標系

2. CGContextTranslateCTM(CGContextRef c, CGFloat tx, CGFloat ty)方法可以相對原點平移上下文座標系

3. CGContextScaleCTM(CGContextRef c, CGFloat sx, CGFloat sy)方法可以縮放上下文座標系

 

注意:

轉換座標系前,使用CGContextSaveGState(CGContextRef c)儲存當前上下文狀態

座標系轉換後,使用CGContextRestoreGState(CGContextRef c)可以恢複之前儲存的上下文狀態

 

Quartz基本繪圖方法

CGContextBeginPath開始一個新路徑CGContextMoveToPoint設定路徑的起點CGContextClosePath關閉路徑CGContextAddPath添加路徑CGContextAddLineToPoint在指定點添加線CGContextAddLines添加多條線CGContextAddRect添加矩形CGContextAddRects添加多個矩形CGContextAddEllipseInRect在矩形地區中添加橢圓CGContextAddArc添加圓弧CGContextAddArcToPoint在指定點添加圓弧CGContextAddCurveToPoint在指定點添加曲線CGContextDrawPath繪製路徑CGContextFillPath實心路徑CGContextFillRect實心矩形CGContextFillRects多個實心矩形CGContextFillEllipseInRect在矩形地區中繪製實心橢圓CGContextStrokePath空心路徑CGContextStrokeRect空心矩形CGContextStrokeRectWithWidth使用寬度繪製空心矩形CGContextStrokeEllipseInRect在矩形地區中繪製空心橢圓CGContextSetLineWidth 設定線寬CGContextSetBlendMode 設定混合模式CGContextSetShouldAntialias 設定消除鋸齒效果CGContextSetLineCap 設定線條收尾點樣式CGContextSetLineJoin 設定線條連接點樣式CGContextSetLineDash 設定虛線

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.