標籤: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 設定虛線