cgcontextref context = uigraphicsgetcurrentcontext(); 設定上下文
cgcontextmovetopoint 開始畫線
cgcontextaddlinetopoint 畫直線
cgcontextaddellipseinrect 畫一橢圓
cgcontextsetlinecap 設定線條終點形狀
cgcontextsetlinedash 畫虛線
cgcontextaddrect 畫一方框
cgcontextstrokerect 指定矩形
cgcontextstrokerectwithwidth 指定矩形線寬度
cgcontextstrokelinesegments 一些直線
cgcontextaddarc 畫已曲線 前倆店為中心 中間倆店為起始弧度 最後一資料為0則順時針畫 1則逆時針
cgcontextaddarctopoint(context,0,0, 2, 9, 40);//先畫倆條線從point 到 弟1點 , 從弟1點到弟2點的線 切割裡面的圓
cgcontextsetshadowwithcolor 設定陰影
cgcontextsetrgbfillcolor 這隻填充顔色
cgcontextsetrgbstrokecolor 畫筆顔色設定
cgcontextsetfillcolorspace 顔色空間填充
cgconextsetstrokecolorspace 顔色空間畫筆設定
cgcontextfillrect 補充目前填充顔色的rect
cgcontextsetalaha 透明度
cgcontexttranslatectm 改變畫布位置
cgcontextsetlinewidth 設定線的寬度
cgcontextaddrects 畫多個線
cgcontextaddquadcurvetopoint 畫曲線
cgcontextstrokepath 開始繪制圖檔
cgcontextdrawpath 設定繪制模式
cgcontextclosepath 封閉目前線路
cgcontexttranslatectm(context, 0, rect.size.height); cgcontextscalectm(context, 1.0, -1.0);反轉畫布
cgcontextsetinterpolationquality 背景内置顔色品質等級
cgimagecreatewithimageinrect 從原圖檔中取小圖
//字元串的 寫入可用 nsstring本身的畫圖方法
-(cgsize)drawinrect:(cgrect)rect
withfont:(uifont *)font
linebreakmode:(uilinebreakmode)linebreakmode
alignment:(uitextalignment)alignment;來寫進去即可
//對圖檔放大縮小的功能就是慢了點
uigraphicsbeginimagecontext(newsize);
uiimage* newimage = uigraphicsgetimagefromcurrentimagecontext();
uigraphicsendimagecontext();
cgcolorgetcomponents() 傳回顔色的各個直 以及透明度 可用隻讀const float 來接收 是個數組
//畫圖檔
cgimageref image=cgimageretain(img.cgimage);
cgcontextdrawimage(context, cgrectmake(10.0, height - 100.0, 90.0, 90.0), image);
//實作逐變顔色填充方法 cgcontextclip(context);
cgcolorspaceref rgb = cgcolorspacecreatedevicergb();
cgfloat colors[] =
{
204.0 / 255.0, 224.0 / 255.0, 244.0 / 255.0, 1.00,
29.0 / 255.0, 156.0 / 255.0, 215.0 / 255.0, 1.00,
0.0 / 255.0, 50.0 / 255.0, 126.0 / 255.0, 1.00,
};
cggradientref gradient = cggradientcreatewithcolorcomponents(rgb, colors, null, sizeof(colors)/(sizeof(colors[0])*4));
cgcolorspacerelease(rgb);
cgcontextdrawlineargradient(context, gradient,cgpointmake(0.0,0.0) ,cgpointmake(0.0,self.frame.size.height),
kcggradientdrawsbeforestartlocation);
//注: 畫完圖後,必須
先用cgcontextstrokepath來描線,即形狀
後用cgcontextfillpath來填充形狀内的顔色.
//填充一個路徑的時候,路徑裡面的子路徑都是獨立填充的。
//假如是重疊的路徑,決定一個點是否被填充,有兩種規則
1,nonzero winding number rule:非零繞數規則,假如一個點被從左到右跨過,計數器+1,從右到左跨過,計數器-1,最後,如果結果是0,那麼不填充,如果是非零,那麼填充。
2,even-odd rule: 奇偶規則,假如一個點被跨過,那麼+1,最後是奇數,那麼要被填充,偶數則不填充,和方向沒有關系。
cgcontexteofillpath //使用奇偶規則填充目前路徑
cgcontextfillpath //使用非零繞數規則填充目前路徑
cgcontextfillrect //填充指定的矩形
cgcontextfillrects //填充指定的一些矩形
cgcontextfillellipseinrect //填充指定矩形中的橢圓
cgcontextdrawpath //兩個參數決定填充規則,kcgpathfill表示用非零繞數規則,kcgpatheofill表示用奇偶規則,kcgpathfillstroke表示填充,kcgpatheofillstroke表示描線,不是填充
//設定當一個顔色覆寫上另外一個顔色,兩個顔色怎麼混合
//預設方式是
result = (alpha * foreground) + (1 - alpha) * background
cgcontextsetblendmode :設定blend mode.
cgcontextsavegstate :儲存blend mode.
cgcontextrestoregstate:在沒有儲存之前,用這個函數還原blend mode.
cgcontextsetblendmode 混合倆種顔色