Core Graphics 全面介紹

CoreGraphics也稱為Quartz 2D 是UIKit下的主要繪圖系統(tǒng)纠屋,頻繁的用于繪制自定義視圖。Core Graphics是高度集成于UIView和其他UIKit部分的嗽冒。Core Graphics數(shù)據(jù)結(jié)構(gòu)和函數(shù)可以通過前綴CG來識別丢烘。

先簡單粗暴,上五個常用實(shí)例:

視圖可以通過子視圖扭粱、圖層或?qū)崿F(xiàn)drawRect:方法來表現(xiàn)內(nèi)容糕簿,如果說實(shí)現(xiàn)了drawRect:方法探入,那么最好就不要混用其他方法了,如圖層和子視圖懂诗。自定義繪圖大部分是由UIKit或者Core Graphics來實(shí)現(xiàn)的蜂嗽。

實(shí)例:

1、繪制文本:
    CGContextRef context4 = UIGraphicsGetCurrentContext();
    NSString *string = @"我是文本";
    NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:35], NSFontAttributeName, [UIColor orangeColor], NSForegroundColorAttributeName, nil];
    [string drawAtPoint:CGPointMake(30, 450) withAttributes:attrs];
    CGContextSaveGState(context4);
2殃恒、繪制圖片:
 UIImage * img = [UIImage imageNamed:@"bg"];
 [img drawInRect:CGRectMake(20, 500, 50, 200)];
3徒爹、漸變效果:
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    NSArray *colors = @[(__bridge id)[UIColor colorWithRed:0.3 green:0.0 blue:0.0 alpha:0.2].CGColor,
                        (__bridge id)[UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:0.8].CGColor];
    const CGFloat locations[] = {0.0, 1.0};
    
    CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colors, locations);
    CGContextDrawLinearGradient(context, gradient, CGPointMake(200, 150), CGPointMake(250, 200), 0); //開始繪制
    //釋放資源
    CGGradientRelease(gradient);
    CGColorSpaceRelease(colorSpace);
4、畫矩形:
    CGContextRef context3 = UIGraphicsGetCurrentContext();
    CGContextAddRect(context, CGRectMake(200, 150, 50, 50));
    [[UIColor orangeColor]setStroke];
    CGContextSetLineWidth(context3, 3);
    CGContextDrawPath(context3, kCGPathStroke);
    CGContextSaveGState(context3);
5芋类、畫線:
    [[UIColor redColor] setFill];
    [[UIColor blackColor] setStroke];
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 5.0f);
    CGContextSetLineJoin(context, kCGLineJoinRound);//設(shè)置連接點(diǎn)樣式。
    CGContextMoveToPoint(context, 50, 100);
    CGContextAddLineToPoint(context, 70, 300);
    CGContextAddLineToPoint(context, 80, 200);
    CGContextClosePath(context);
    CGContextDrawPath(context, kCGPathFillStroke);
    CGContextSaveGState(context);//保存上下文狀態(tài)
    
    
    CGContextRef context2 = UIGraphicsGetCurrentContext();
    [[UIColor brownColor]set];
    CGContextSetLineWidth(context2, 3);
    CGContextMoveToPoint(context2, 200, 100);
    CGContextAddLineToPoint(context2, 300, 100);
    CGContextAddLineToPoint(context2, 350, 250);
    CGContextStrokePath(context2);
    CGContextSaveGState(context2);

CGContextRef

Graphics Context是圖形上下文,也可以理解為一塊畫布,我們可以在上面進(jìn)行繪畫操作,繪制完成后,將畫布放到我們的view中顯示即可,view看作是一個畫框界阁。
接下來開始CGContextRef的相關(guān)方法介紹侯繁,方法較多,大家可篩選重點(diǎn)來看泡躯。

相關(guān)枚舉值:
  • 線段端點(diǎn)的繪制形狀:
typedef CF_ENUM(int32_t, CGLineJoin) {
    kCGLineJoinMiter, // 這是默認(rèn)的屬性值贮竟。該方格的連接點(diǎn)形狀如圖1所示。
    kCGLineJoinRound, // 稍微圓角, 該方格的連接點(diǎn)形狀如圖2所示较剃。
    kCGLineJoinBevel  // 斜角,該方格的連接點(diǎn)形狀如圖3所示咕别。
};

設(shè)置方法:

void CGContextSetLineCap(CGContextRef__nullable c, CGLineCap cap)
  • 連接點(diǎn)樣式:
typedef CF_ENUM(int32_t, CGLineJoin) {
    kCGLineJoinMiter, // 這是默認(rèn)的屬性值。該方格的連接點(diǎn)形狀如圖1所示写穴。
    kCGLineJoinRound, // 稍微圓角, 該方格的連接點(diǎn)形狀如圖2所示惰拱。
    kCGLineJoinBevel  // 斜角,該方格的連接點(diǎn)形狀如圖3所示。
};

[圖片上傳失敗...(image-b758c4-1557146885538)]

設(shè)置方法:

void CGContextSetLineJoin(CGContextRef__nullable c, CGLineJoin join)

當(dāng)把連接點(diǎn)風(fēng)格設(shè)為meter風(fēng)格時(shí)啊送,該方法用于控制銳角箭頭的長度:

void CGContextSetMiterLimit(CGContextRef__nullable c, CGFloat limit)
  • 繪制模式:
typedef CF_ENUM (int32_t, CGPathDrawingMode) {
  kCGPathFill,//只有填充(非零纏繞數(shù)填充)偿短,不繪制邊框  如圖1
  kCGPathEOFill,//奇偶規(guī)則填充(多條路徑交叉時(shí),奇數(shù)交叉填充馋没,偶交叉不填充)如圖2
  kCGPathStroke,        // 只有邊框  如圖3
  kCGPathFillStroke,    // 既有邊框又有填充  如圖4
  kCGPathEOFillStroke   // 奇偶填充并繪制邊框  如圖5
};

[圖片上傳失敗...(image-6d9139-1557146885538)]

繪制的時(shí)候可以用到:

void CGContextDrawPath(CGContextRef__nullable c, CGPathDrawingMode mode)
方法-狀態(tài)相關(guān):
  • 保存繪圖狀態(tài):
//為了讓開發(fā)者在進(jìn)行坐標(biāo)變換時(shí)無須計(jì)算多次坐標(biāo)變換后的累加結(jié)果昔逗,Quartz 2D還提供了如下兩個方法來保存、恢復(fù)繪圖狀態(tài)
 保存CGContextRef當(dāng)前的繪圖狀態(tài)篷朵,方便以后恢復(fù)該狀態(tài)
 // 需要說明的是勾怒,CGContextSaveGState()函數(shù)保存的繪圖狀態(tài)婆排,不僅包括當(dāng)前坐標(biāo)系統(tǒng)的狀態(tài),也包括當(dāng)前設(shè)置的填充風(fēng)格笔链、線條風(fēng)格段只、陰影風(fēng)格等各種繪圖狀態(tài)。但 CGContextSaveGState()函數(shù)不會保存當(dāng)前繪制的圖形
void CGContextSaveGState(CGContextRef__nullable c) 
  • 把CGContextRef恢復(fù)到最近一次保存的狀態(tài):
void CGContextRestoreGState(CGContextRef__nullable c)
方法-更改坐標(biāo)系統(tǒng):
  • 縮放坐標(biāo)系統(tǒng):
//該方法控制坐標(biāo)系統(tǒng)水平方向上縮放 sx卡乾,垂直方向上縮放 sy翼悴。在縮放后的坐標(biāo)系統(tǒng)上繪制圖形時(shí),所有點(diǎn)的 X 坐標(biāo)都相當(dāng)于乘以 sx 因子幔妨,所有點(diǎn)的 Y 坐標(biāo)都相當(dāng)于乘以 sy因子鹦赎。
void CGContextScaleCTM(CGContextRef__nullable c, CGFloat sx, CGFloat sy)
  • 平移坐標(biāo)系統(tǒng):
// 該方法相當(dāng)于把原來位于 (0, 0) 位置的坐標(biāo)原點(diǎn)平移到 (tx, ty)點(diǎn)。在平移后的坐標(biāo)系統(tǒng)上繪制圖形時(shí)误堡,所有坐標(biāo)點(diǎn)的 X坐標(biāo)都相當(dāng)于增加了 tx古话,所有點(diǎn)的 Y坐標(biāo)都相當(dāng)于增加了 ty。
void CGContextTranslateCTM(CGContextRef__nullable c,
    CGFloat tx, CGFloat ty)
  • 旋轉(zhuǎn)坐標(biāo)系統(tǒng):
 //該方法控制坐標(biāo)系統(tǒng)旋轉(zhuǎn) angle 弧度锁施。在縮放后的坐標(biāo)系統(tǒng)上繪制圖形時(shí)陪踩,所有坐標(biāo)點(diǎn)的 X、Y坐標(biāo)都相當(dāng)于旋轉(zhuǎn)了 angle弧度之后的坐標(biāo)悉抵。
void CGContextRotateCTM(CGContextRef__nullable c, CGFloat angle)
  • 矩陣變換

通過矩陣設(shè)置變換:

 //使用 transform變換矩陣對 CGContextRef的坐標(biāo)系統(tǒng)執(zhí)行變換肩狂,通過使用坐標(biāo)矩陣可以對坐標(biāo)系統(tǒng)執(zhí)行任意變換。
void CGContextConcatCTM(CGContextRef__nullable c,
    CGAffineTransform transform)

拿到變換中的矩陣:

CGAffineTransform CGContextGetCTM(CGContextRef__nullable c)
方法-設(shè)置:
  • 設(shè)置繪制直線姥饰、邊框時(shí)的線條寬度:
void CGContextSetLineWidth(CGContextRef__nullable c, CGFloat width)
  • 設(shè)置虛線模式:
 // Linedash pattern(虛線模式)允許我們沿著描邊繪制虛線傻谁。我們通過在CGContextSetLineDash結(jié)構(gòu)體中指定虛線數(shù)組和虛線相位來控制虛線的大小及位置。
其中l(wèi)engths屬性指定了虛線段的長度列粪,該值是在繪制片斷與未繪制片斷之間交替审磁。phase屬性指定虛線模式的起始點(diǎn)。圖3-11顯示了虛線模式:
void CGContextSetLineDash(CGContextRef__nullable c, CGFloat phase,const CGFloat *__nullable lengths, size_t count)
  • 設(shè)置彎曲的路徑中的圖形上下文的準(zhǔn)確性
void CGContextSetFlatness(CGContextRef__nullable c, CGFloat flatness)
  • 設(shè)置全局透明度
void CGContextSetAlpha(CGContextRef__nullable c, CGFloat alpha)
  • 設(shè)置CGContextRef的疊加模式岂座。Quartz 2D支持多種疊加模式:
void CGContextSetBlendMode(CGContextRef __nullable c, CGBlendMode mode)
方法-路徑變換:
  • 開創(chuàng)新路徑:
void CGContextBeginPath(CGContextRef__nullable c)
  • 開始一個新的子路徑起點(diǎn):
void CGContextMoveToPoint(CGContextRef__nullable c,
    CGFloat x, CGFloat y)
  • 添加一條直線段:
void CGContextAddLineToPoint(CGContextRef__nullable c,
    CGFloat x, CGFloat y)
  • 添加多條直線路徑:
void CGContextAddLines(CGContextRef__nullable c,
    const CGPoint * __nullable points, size_t count)
  • 添加一個三次bezier曲線:
/**
 *  從當(dāng)前添加一個三次Bezier曲線
 *  @param cp1x 控制點(diǎn)1 x坐標(biāo)
 *  @param cp1y 控制點(diǎn)1 y坐標(biāo)
 *  @param cp2x 控制點(diǎn)2 x坐標(biāo)
 *  @param cp2y 控制點(diǎn)2 y坐標(biāo)
 *  @param x    直線的終點(diǎn) x坐標(biāo)
 *  @param y    直線的終點(diǎn) y坐標(biāo)
 */
void CGContextAddCurveToPoint(CGContextRef__nullable c, CGFloat cp1x, CGFloat cp1y, CGFloat cp2x, CGFloat cp2y, CGFloat x, CGFloat y)    
  • 添加一個二次bezier曲線:
/**
 *  從當(dāng)前添加一個二次Bezier曲線
 *  @param cpx 控制點(diǎn) x坐標(biāo)
 *  @param cpy 控制點(diǎn) y坐標(biāo)
 *  @param x   直線的終點(diǎn) x坐標(biāo)
 *  @param y   直線的終點(diǎn) y坐標(biāo)
 */
void CGContextAddQuadCurveToPoint(CGContextRef__nullable c, CGFloat cpx, CGFloat cpy,CGFloat x,CGFloat y)
  • 關(guān)閉子路徑态蒂,并連接當(dāng)前點(diǎn)和起點(diǎn)。
void CGContextClosePath(CGContextRef__nullable c)
  • 添加矩形路徑:
void CGContextAddRect(CGContextRef__nullable c, CGRect rect)
  • 添加多個矩形路徑:
void CGContextAddRects(CGContextRef__nullable c,
    const CGRect * __nullable rects, size_t count)
  • 添加一個橢圓:
void CGContextAddEllipseInRect(CGContextRef__nullable c, CGRect rect)
  • 添加一個弧形對象:
/**
 *  添加弧形對象
 *  @param x          中心點(diǎn)x坐標(biāo)
 *  @param y          中心點(diǎn)y坐標(biāo)
 *  @param radius     半徑
 *  @param startAngle 起始弧度
 *  @param endAngle   終止弧度
 *  @param clockwise  是否逆時(shí)針繪制费什,0則順時(shí)針繪制
 */
void CGContextAddArc(CGContextRef__nullable c, CGFloat x,CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle,int clockwise)
  • 使用一個序列的三次貝塞爾曲線創(chuàng)建一個患鼗帧:

    原理:首先畫兩條線,這兩條線分別是 current point to (x1,y1)和(x1,y1) to (x2,y2).這樣就是出現(xiàn)一個以(x1,y1)為頂點(diǎn)的兩條射線鸳址,然后定義半徑長度赘那,這個半徑是垂直于兩條射線的,這樣就能決定一個圓了氯质,如果當(dāng)前點(diǎn)和第一個切點(diǎn)的弧(起點(diǎn))是不平等的,那么會添加一條直線段從當(dāng)前指向第一個切點(diǎn)募舟。弧的終點(diǎn)成為新的當(dāng)前點(diǎn)的路徑闻察。


 void CGContextAddArcToPoint(CGContextRef__nullable c, CGFloat x1, CGFloat y1, CGFloat x2, CGFloat y2, CGFloat radius) 

  • 添加路徑到上下文:
void CGContextAddPath(CGContextRef__nullable c, CGPathRef__nullable path)
  • 使用繪制當(dāng)前路徑時(shí)覆蓋的區(qū)域作為當(dāng)前CGContextRef中的新路徑

    舉例來說拱礁,假如當(dāng)前CGContextRef包含一個圓形路徑且線寬為10琢锋,調(diào)用該方法后,當(dāng)前CGContextRef將包含一個環(huán)寬為10的環(huán)形路徑

  • 填充該路徑包圍的區(qū)域:

void CGContextFillPath(CGContextRef__nullable c)

  • 使用奇偶規(guī)則來填充該路徑包圍的區(qū)域:

奇偶規(guī)則指:如果某個點(diǎn)被路徑包圍了奇數(shù)次呢灶,系統(tǒng)繪制該點(diǎn)吴超;如果被路徑包圍了偶數(shù)次,系統(tǒng)不繪制

void CGContextEOFillPath(CGContextRef__nullable c)

  • 使用當(dāng)前 CGContextRef設(shè)置的線寬繪制路徑
void CGContextStrokePath(CGContextRef__nullable c)

  • 填充rect代表的矩形
void CGContextFillRect(CGContextRef__nullable c, CGRect rect)

  • 填充多個矩形:
void CGContextFillRects(CGContextRef__nullable c,
    const CGRect * __nullable rects, size_t count)

  • 使用當(dāng)前 CGContextRef設(shè)置的線寬繪制矩形框
void CGContextStrokeRect(CGContextRef__nullable c, CGRect rect)

  • 使用指定線寬繪制矩形框:
void CGContextStrokeRectWithWidth(CGContextRef__nullable c,
    CGRect rect, CGFloat width)

  • 擦除指定矩形區(qū)域上繪制的圖形:
void CGContextClearRect(CGContextRef__nullable c, CGRect rect)

  • 填充rect矩形的內(nèi)切橢圓區(qū)域:
void CGContextFillEllipseInRect(CGContextRef__nullable c,CGRect rect)

  • 使用當(dāng)前 CGContextRef設(shè)置的線寬繪制rect矩形的內(nèi)切橢圓:
void CGContextStrokeEllipseInRect(CGContextRef__nullable c, CGRect rect)

  • 繪制多個線段鸯乃。

該方法需要傳入2N個CGPoint組成的數(shù)組鲸阻,其中1、2個點(diǎn)組成第一條線段缨睡,3鸟悴、4個點(diǎn)組成第2條線段,以此類推.

void CGContextStrokeLineSegments(CGContextRef__nullable c,const CGPoint * __nullable points, size_t count)

  • 修改當(dāng)前剪切路徑:
/* 修改當(dāng)前剪貼路徑奖年,使用非零繞數(shù)規(guī)則细诸。 */
void CGContextClip(CGContextRef__nullable c)

/* 修改當(dāng)前剪貼路徑,使用奇偶規(guī)則陋守。 */
void CGContextEOClip(CGContextRef__nullable c)

  • 剪切遮罩處理(針對圖片)
void CGContextClipToMask(CGContextRef__nullable c, CGRect rect, CGImageRef__nullable mask)

  • 剪切矩形外的部分.
/* 剪切指定矩形區(qū)域外的部分. */
void CGContextClipToRect(CGContextRef__nullable c, CGRect rect)

/* 剪切指定多個矩形區(qū)域外的部分 */
void CGContextClipToRects(CGContextRef__nullable c,const CGRect *  rects, size_t count)

  • 使用指定顏色來設(shè)置該CGContextRef的填充顏色
void CGContextSetFillColorWithColor(CGContextRef__nullable c,CGColorRef __nullable color)
    
  • 使用指定顏色來設(shè)置該CGContextRef的線條顏色
void CGContextSetStrokeColorWithColor(CGContextRef__nullable c,CGColorRef __nullable color)

方法-讀日鸸蟆:
  • 返回一個非空的路徑中的當(dāng)前點(diǎn):
CGPoint CGContextGetPathCurrentPoint(CGContextRef__nullable c)

  • 返回當(dāng)前路徑的最小矩形:
CGRect CGContextGetPathBoundingBox(CGContextRef__nullable c)
  • 返回拷貝后的一個path:
CGPathRef __nullableCGContextCopyPath(CGContextRef__nullable c)

  • 獲取到了需要繪制的圖形上下文的位置與大小
CGRect CGContextGetClipBoundingBox(CGContextRef__nullable c)
方法-判斷
  • 表示目前的路徑是否包含任何的子路徑
bool CGContextIsPathEmpty(CGContextRef__nullable c)
  • 檢查當(dāng)前路徑是否包含指定的點(diǎn):
bool CGContextPathContainsPoint(CGContextRef__nullable c,
    CGPoint point, CGPathDrawingMode mode)
其它方法:
/** Color space functions. **/

/* 顏色空間填充 */
void CGContextSetFillColorSpace(CGContextRef__nullable c, CGColorSpaceRef__nullable space)

/* 設(shè)置線框顏色空間 */

void CGContextSetStrokeColorSpace(CGContextRef__nullable c,
    CGColorSpaceRef __nullable space)

/** Color functions. **/

/* 設(shè)置填充顏色空間 CGFloat redColor[4] = {1.0,0,0,1.0};*/
void CGContextSetFillColor(CGContextRef__nullable c,const CGFloat *__nullable components(redColor))

/* 設(shè)置畫筆顏色 CGFloat redColor[4] = {1.0,0,0,1.0};*/
void CGContextSetStrokeColor(CGContextRef__nullable c,const CGFloat *__nullable components(redColor))

/** Pattern functions. **/

/* 
 設(shè)置該CGContextRef使用位圖填充*/
void CGContextSetFillPattern(CGContextRef__nullable c, CGPatternRef__nullable pattern,const CGFloat * __nullable components)

/* 
 設(shè)置該CGContextRef使用位圖繪制線條、邊框*/
void CGContextSetStrokePattern(CGContextRef__nullable c, CGPatternRef__nullable pattern,const CGFloat * __nullable components)

/*  
 設(shè)置該CGContextRef采用位圖填充的相位*/
void CGContextSetPatternPhase(CGContextRef__nullable c, CGSize phase)

/** Color convenience functions. **/

/* 
 使用灰色來設(shè)置該CGContextRef的填充顏色*/
void CGContextSetGrayFillColor(CGContextRef__nullable c,
    CGFloat gray, CGFloat alpha)

/*  
 使用灰色來設(shè)置該CGContextRef的線條顏色*/
void CGContextSetGrayStrokeColor(CGContextRef__nullable c,
    CGFloat gray, CGFloat alpha)

/*  
 使用RGB顏色模式來設(shè)置該CGContextRef的填充顏色*/
void CGContextSetRGBFillColor(CGContextRef__nullable c, CGFloat red,
    CGFloat green, CGFloat blue, CGFloat alpha)

/* 設(shè)置畫筆顏色 */
void CGContextSetRGBStrokeColor(CGContextRef__nullable c,
    CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha)

/* 
 使用CMYK顏色模式來設(shè)置該CGContextRef的填充顏色*/
void CGContextSetCMYKFillColor(CGContextRef__nullable c,
    CGFloat cyan, CGFloat magenta, CGFloat yellow, CGFloat black, CGFloat alpha)

/* 
 使用CMYK顏色模式來設(shè)置該CGContextRef的線條顏色*/
void CGContextSetCMYKStrokeColor(CGContextRef__nullable c,
    CGFloat cyan, CGFloat magenta, CGFloat yellow, CGFloat black, CGFloat alpha)

/** Rendering intent. **/

/* 在當(dāng)前圖形狀態(tài)設(shè)置渲染意向 */
void CGContextSetRenderingIntent(CGContextRef__nullable c,
    CGColorRenderingIntent intent)

/** Image functions. **/

/* 繪制圖像到圖形上下文中 */
void CGContextDrawImage(CGContextRef__nullable c, CGRect rect,
    CGImageRef __nullable image)

/* 重復(fù)繪制的圖像水评,擴(kuò)展到提供的矩形猩系,填補(bǔ)當(dāng)前剪輯區(qū)域。 */
void CGContextDrawTiledImage(CGContextRef__nullable c, CGRect rect,
    CGImageRef __nullable image)

/* 
  獲取當(dāng)前CGContextRef在放大圖片時(shí)的插值質(zhì)量*/
CGInterpolationQuality CGContextGetInterpolationQuality(CGContextRef__nullable c)

/* 
  設(shè)置圖形上下文的插值質(zhì)量水平中燥。*/
void CGContextSetInterpolationQuality(CGContextRef__nullable c,
    CGInterpolationQuality quality)

/** Shadow support. **/

/*  
 設(shè)置陰影在X寇甸、Y方向上的偏移,以及模糊度和陰影的顏色
*/
void CGContextSetShadowWithColor(CGContextRef__nullable c,
    CGSize offset, CGFloat blur, CGColorRef __nullable color)


/*  
 設(shè)置陰影在X褪那、Y方向上的偏移,以及模糊度(blur值越大式塌,陰影越模糊)博敬。該函數(shù)沒有設(shè)置陰影顏色,
默認(rèn)使用1/3透明的黑色(即RGBA{0, 0, 0, 1.0/3.0})作為陰影顏色
*/

void CGContextSetShadow(CGContextRef__nullable c, CGSize offset,
    CGFloat blur)


/** Gradient and shading functions. **/

/* 繪制一個漸變填充定義的出發(fā)點(diǎn)和落腳點(diǎn)沿線變化峰尝。*/
void CGContextDrawLinearGradient(CGContextRef__nullable c,
    CGGradientRef __nullable gradient, CGPoint startPoint, CGPoint endPoint,
    CGGradientDrawingOptions options)


/* 繪制一個沿著由所提供的開始和結(jié)束的圓限定的區(qū)域變化的漸變填充偏窝。 */
void CGContextDrawRadialGradient(CGContextRef__nullable c,
    CGGradientRef __nullable gradient, CGPoint startCenter, CGFloat startRadius,
    CGPoint endCenter, CGFloat endRadius, CGGradientDrawingOptions options)


/* 使用指定的陰影的背景,填充剪切路徑武学。 */
void CGContextDrawShading(CGContextRef __nullable c,
    __nullable CGShadingRef shading)


/** Text functions. **/

/* 設(shè)置當(dāng)前字符間距. */
void CGContextSetCharacterSpacing(CGContextRef__nullable c,
    CGFloat spacing)


/* 設(shè)置要繪制文本的位置祭往。 */
void CGContextSetTextPosition(CGContextRef__nullable c,
    CGFloat x, CGFloat y)


/* 返回在繪制文本的位置。 */
CGPoint CGContextGetTextPosition(CGContextRef __nullable c)


/* 設(shè)置當(dāng)前文本矩陣火窒。 */
void CGContextSetTextMatrix(CGContextRef__nullable c,
    CGAffineTransform t)

/* 返回當(dāng)前文本矩陣硼补。 */
CGAffineTransform CGContextGetTextMatrix(CGContextRef__nullable c)

/* 設(shè)置當(dāng)前文本的繪圖模式。 */
void CGContextSetTextDrawingMode(CGContextRef__nullable c,
    CGTextDrawingMode mode)

/* 設(shè)置上下文的字體 */
void CGContextSetFont(CGContextRef__nullable c,
    CGFontRef __nullable font)

/* 設(shè)置上下文的字體大小熏矿。 */
void CGContextSetFontSize(CGContextRef__nullable c, CGFloat size)


/* 在所提供的位置繪制字形已骇。 */
void CGContextShowGlyphsAtPositions(CGContextRef__nullable c,
    const CGGlyph * __nullable glyphs, const CGPoint * __nullable Lpositions,
    size_t count)


/** PDF functions. **/

/* 繪制一個PDF頁面到當(dāng)前的用戶空間离钝。 */
void CGContextDrawPDFPage(CGContextRef__nullable c,
    CGPDFPageRef __nullable page)


/** Output page functions. **/

/* 基于頁面的圖形上下文中開始了新的一頁。 */
void CGContextBeginPage(CGContextRef__nullable c,const CGRect *__nullable mediaBox)


/* 在基于頁面的圖形上下文結(jié)束當(dāng)前的頁面褪储。 */
void CGContextEndPage(CGContextRef__nullable c)


/** Context functions. **/

/* 圖形上下文的引用計(jì)數(shù)+1 */
CGContextRef __nullableCGContextRetain(CGContextRef__nullable c)


/* 圖形上下文的引用計(jì)數(shù)-1. */
void CGContextRelease(CGContextRef__nullable c)


/* 強(qiáng)制所有掛起的繪圖操作在一個窗口上下文中立即被渲染到目標(biāo)設(shè)備 */
void CGContextFlush(CGContextRef__nullable c)


/* 將一個窗口的圖像上下文內(nèi)容更新卵渴,即所有的繪圖操作都會在下次同步到窗口上. */
void CGContextSynchronize(CGContextRef__nullable c)


/** Antialiasing functions. **/

/*  
 設(shè)置該CGContextRef是否應(yīng)該抗鋸齒(即光滑圖形曲線邊緣)*/
void CGContextSetShouldAntialias(CGContextRef__nullable c,
    bool shouldAntialias)

/* 
 設(shè)置該CGContextRef是否允許抗鋸齒*/
void CGContextSetAllowsAntialiasing(CGContextRef__nullable c,
    bool allowsAntialiasing)

/** Font display functions. **/

/*  
 設(shè)置該CGContextRef是否允許光滑字體*/
void CGContextSetShouldSmoothFonts(CGContextRef__nullable c,
    bool shouldSmoothFonts)

/* 
 設(shè)置該CGContextRef是否允許光滑字體*/
void CGContextSetAllowsFontSmoothing(CGContextRef__nullable c,
    bool allowsFontSmoothing)

// Enables or disables subpixel positioning in a graphics context.
void CGContextSetShouldSubpixelPositionFonts(
    CGContextRef __nullable c, bool shouldSubpixelPositionFonts)


// Sets whether or not to allow subpixel positioning for a graphics context
void CGContextSetAllowsFontSubpixelPositioning(
    CGContextRef __nullable c, bool allowsFontSubpixelPositioning)


// Enables or disables subpixel quantization in a graphics context.
void CGContextSetShouldSubpixelQuantizeFonts(
    CGContextRef __nullable c, bool shouldSubpixelQuantizeFonts)


// Sets whether or not to allow subpixel quantization for a graphics context
void CGContextSetAllowsFontSubpixelQuantization(
    CGContextRef __nullable c, bool allowsFontSubpixelQuantization)


/** Transparency layer support. **/

/* 開始一個透明層。
 直到相應(yīng)的調(diào)用CGContextEndTransparencyLayer鲤竹,在指定范圍內(nèi)的所有后續(xù)繪制操作組合到一個完全透明的背景(它被視為一個單獨(dú)的目標(biāo)緩沖區(qū)從上下文)浪读。

在透明層中繪制需要三步:
 1.  調(diào)用函數(shù) CGContextBeginTransparencyLayer
 2.  在透明層中繪制需要組合的對象
 3.  調(diào)用函數(shù) CGContextEndTransparencyLayer*/
void CGContextBeginTransparencyLayer(CGContextRef__nullable c,
    CFDictionaryRef __nullable auxiliaryInfo)


/* 開始透明度層,它的邊界是指定的矩形辛藻,其內(nèi)容是有界的碘橘。 */
void CGContextBeginTransparencyLayerWithRect(
    CGContextRef __nullable c, CGRect rect, CFDictionaryRef__nullable auxInfo)


/* 結(jié)束一個透明層。 */
void CGContextEndTransparencyLayer(CGContextRef__nullable c)

/** User space to device space tranformations. **/

/*  獲取Quartz轉(zhuǎn)換用戶空間和設(shè)備空間的仿射變換 */
CGAffineTransform CGContextGetUserSpaceToDeviceSpaceTransform(CGContextRef__nullable c)

/*———— 點(diǎn) ————*/
/* 將一個CGPoint數(shù)據(jù)結(jié)構(gòu)從一個空間變換到另一個空間(DeviceSpace). */
CGPoint CGContextConvertPointToDeviceSpace(CGContextRef__nullable c,
    CGPoint point)

/* 將一個CGPoint數(shù)據(jù)結(jié)構(gòu)從一個空間變換到另一個空間(UserSpace). */
CGPoint CGContextConvertPointToUserSpace(CGContextRef__nullable c,
    CGPoint point)

/*———— 大小 ————*/
/* 將一個CGSize數(shù)據(jù)結(jié)構(gòu)從一個空間變換到另一個空間(DeviceSpace). */
CGSize CGContextConvertSizeToDeviceSpace(CGContextRef__nullable c, CGSize size)


/* 將一個CGSize數(shù)據(jù)結(jié)構(gòu)從一個空間變換到另一個空間(UserSpace). */
CGSize CGContextConvertSizeToUserSpace(CGContextRef__nullable c, CGSize size)


/*———— 矩形 ————*/
/* 將一個CGPoint數(shù)據(jù)結(jié)構(gòu)從一個空間變換到另一個空間(DeviceSpace)揩尸。 */

CGRect CGContextConvertRectToDeviceSpace(CGContextRef__nullable c,
    CGRect rect)

/* 將一個CGPoint數(shù)據(jù)結(jié)構(gòu)從一個空間變換到另一個空間(UserSpace)蛹屿。 */
CGRect CGContextConvertRectToUserSpace(CGContextRef__nullable c,
    CGRect rect)


/** Deprecated functions. **/
DEPRECATED…
/* 設(shè)置在一個圖形上下文的字體和字體大小 */
void CGContextSelectFont(CGContextRef__nullable c,
    const char *__nullable name, CGFloat size, CGTextEncoding textEncoding)

/* 在當(dāng)前文本位置,由目前的文本矩陣指定的點(diǎn)顯示一個字符數(shù)組岩榆。 */
void CGContextShowText(CGContextRef__nullable c,
    const char *__nullable string, size_t length)

/* 在指定的位置顯示一個字符串错负。 */
void CGContextShowTextAtPoint(CGContextRef__nullable c,
    CGFloat x, CGFloat y, const char * __nullable string, size_t length)

/* 在當(dāng)前文本位置顯示一個數(shù)組的字形。 */
void CGContextShowGlyphs(CGContextRef__nullable c,
    const CGGlyph * __nullable g, size_t count)

/* 在指定的位置顯示一個數(shù)組的字形勇边。 */
void CGContextShowGlyphsAtPoint(CGContextRef__nullable c, CGFloat x,
    CGFloat y, const CGGlyph * __nullable glyphs, size_t count)

/* 繪制具有不同的偏移量的一個數(shù)組字形犹撒。 */
void CGContextShowGlyphsWithAdvances(CGContextRef__nullable c,
    const CGGlyph * __nullable glyphs, const CGSize * __nullable advances,
    size_t count)

/* DEPRECATED; use the CGPDFPage API instead. */
void CGContextDrawPDFDocument(CGContextRef__nullable c, CGRect rect, CGPDFDocumentRef__nullable document,int page)
DEPRECATED…


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市粒褒,隨后出現(xiàn)的幾起案子识颊,更是在濱河造成了極大的恐慌,老刑警劉巖奕坟,帶你破解...
    沈念sama閱讀 218,607評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件祥款,死亡現(xiàn)場離奇詭異,居然都是意外死亡月杉,警方通過查閱死者的電腦和手機(jī)刃跛,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,239評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來苛萎,“玉大人桨昙,你說我怎么就攤上這事‰缜福” “怎么了蛙酪?”我有些...
    開封第一講書人閱讀 164,960評論 0 355
  • 文/不壞的土叔 我叫張陵,是天一觀的道長翘盖。 經(jīng)常有香客問我桂塞,道長,這世上最難降的妖魔是什么馍驯? 我笑而不...
    開封第一講書人閱讀 58,750評論 1 294
  • 正文 為了忘掉前任藐俺,我火速辦了婚禮炊甲,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘欲芹。我一直安慰自己卿啡,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,764評論 6 392
  • 文/花漫 我一把揭開白布菱父。 她就那樣靜靜地躺著颈娜,像睡著了一般。 火紅的嫁衣襯著肌膚如雪浙宜。 梳的紋絲不亂的頭發(fā)上官辽,一...
    開封第一講書人閱讀 51,604評論 1 305
  • 那天,我揣著相機(jī)與錄音粟瞬,去河邊找鬼同仆。 笑死,一個胖子當(dāng)著我的面吹牛裙品,可吹牛的內(nèi)容都是我干的俗批。 我是一名探鬼主播,決...
    沈念sama閱讀 40,347評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼市怎,長吁一口氣:“原來是場噩夢啊……” “哼岁忘!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起区匠,我...
    開封第一講書人閱讀 39,253評論 0 276
  • 序言:老撾萬榮一對情侶失蹤干像,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后驰弄,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體麻汰,經(jīng)...
    沈念sama閱讀 45,702評論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,893評論 3 336
  • 正文 我和宋清朗相戀三年戚篙,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了五鲫。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,015評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡已球,死狀恐怖臣镣,靈堂內(nèi)的尸體忽然破棺而出辅愿,到底是詐尸還是另有隱情智亮,我是刑警寧澤,帶...
    沈念sama閱讀 35,734評論 5 346
  • 正文 年R本政府宣布点待,位于F島的核電站阔蛉,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏癞埠。R本人自食惡果不足惜状原,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,352評論 3 330
  • 文/蒙蒙 一聋呢、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧颠区,春花似錦削锰、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,934評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至朋截,卻和暖如春蛹稍,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背部服。 一陣腳步聲響...
    開封第一講書人閱讀 33,052評論 1 270
  • 我被黑心中介騙來泰國打工唆姐, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人廓八。 一個月前我還...
    沈念sama閱讀 48,216評論 3 371
  • 正文 我出身青樓奉芦,卻偏偏與公主長得像,于是被迫代替她去往敵國和親瘫想。 傳聞我的和親對象是個殘疾皇子仗阅,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,969評論 2 355

推薦閱讀更多精彩內(nèi)容