//取得上下文
? ?CGContextRef context = UIGraphicsGetCurrentContext();
? ?//設(shè)置路徑
? ?CGContextMoveToPoint(context, 10, 15);//起始點(diǎn)
? ?CGContextAddLineToPoint(context, 10, 200);//劃線
? ?CGContextSetLineWidth(context, 5);//寬度
? ?CGContextSetRGBStrokeColor(context, 31/255.0, 118/255.0, 251/255.0, 1);//顏色
? ?CGContextSetLineCap(context, kCGLineCapRound);//線終點(diǎn)
? ?CGContextSetLineJoin(context, kCGLineJoinBevel);//連接點(diǎn)
? ?CGContextClosePath(context);//連接起點(diǎn)和終點(diǎn)
CGContextAddRect(contex, CGRectMake(30, 30, 100, 200));//繪制矩形
? ?CGContextSetRGBFillColor(contex, .3, .3, .3, 1);//設(shè)置填充色
?CGContextAddArc(context, 5, 5, <#半徑#>, <#開始弧度#>, <#結(jié)束弧度#>, <#方向#>);//繪制圓弧
CGContextAddEllipseInRect( context, CGRectMake(50, 50, 200, 100));//繪制橢圓
設(shè)置虛線
? CGContextSetLineDash(<#CGContextRef c#>, <#CGFloat phase#>, <#const CGFloat *lengths#>, <#size_t count#>)//虛線從哪開始,lengths:存放實(shí)點(diǎn)和虛點(diǎn)的數(shù)組(實(shí)截型,虛枝缔,實(shí)权悟。雄妥。悍引。。)count:lengths元素的個數(shù)
? ?CGFloat lenth[] = {1,1,4,5,10};
? ?CGContextSetLineDash(ctx, 0, lenth, 5);
//貝塞爾曲線
? ?//CGContextAddQuadCurveToPoint(context, 200/2, 0, 200, 200);前面兩個是控制點(diǎn)的X,Y鲤屡,后面的是終點(diǎn)的X,Y
? // CGContextAddCurveToPoint(context, 140, 100, 60, -100, 200, 200);前面四個是控制點(diǎn)的X,Y老充,后面的是終點(diǎn)的X,Y
//繪制
CGContextDrawPath(context, kCGPathStroke);
//水印
創(chuàng)建一個基于位圖的上下文
void UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale);
結(jié)束上下文
UIGraphicsEndImageContext();
// ? ?NSMutableAttributedString drawInRect:<#(CGRect)#>
// ? ?NSMutableAttributedString drawAtPoint:<#(CGPoint)#>
// ? ?NSString drawInRect:<#(CGRect)#> withAttributes:<#(NSDictionary *)#>
// ? ?NSString drawAtPoint:<#(CGPoint)#> withAttributes:<#(NSDictionary *)#>
//保存上下文狀態(tài)
? ?CGContextRef context = UIGraphicsGetCurrentContext();
? ?CGContextSaveGState(context);//保存上下文狀態(tài)
? ?CGContextRestoreGState(context);//取出上下文狀態(tài)
CGContextClip(context);//切除上述圖形以外的東西
//路徑
CGMutablePathRef *path = CGPathCreateMutable();//創(chuàng)建路徑
? ?CGPathMoveToPoint(<#CGMutablePathRef path#>, <#const CGAffineTransform *m#>, <#CGFloat x#>, <#CGFloat y#>);//路徑起點(diǎn)
? ?CGPathAddLineToPoint(<#CGMutablePathRef path#>, <#const CGAffineTransform *m#>, <#CGFloat x#>, <#CGFloat y#>)//路徑
? ?CGPathRelease(<#CGPathRef path#>);//釋放路徑
? ?CGPathRetain(<#CGPathRef path#>);//拷貝路徑
//水印
1)創(chuàng)建一個基于位圖的上下文
? ?/*
? ? size:繪制圖片的大小,這里與bgImage
? ? opaque:透明度
? ? scale:放縮
? ? void UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale);
*/
? ? 2)獲取當(dāng)前位圖上下文的圖片
? ?UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
//3)結(jié)束上下文
UIGraphicsEndImageContext();