UIBezierPath and gradient iOS -


i have path values , want make gradient.

here code:

    cgcontextref context = uigraphicsgetcurrentcontext();      cgcontextsetstrokecolorwithcolor(context, [[uicolor colorwithred:245.0/255.0 green:245.0/255.0 blue:171.0/255.0 alpha:0.6] cgcolor]);     cgcontextsetfillcolorwithcolor(context, [[uicolor colorwithred:245.0/255.0 green:245.0/255.0 blue:171.0/255.0 alpha:0.6] cgcolor]);        uibezierpath *apath = [uibezierpath bezierpath];     [apath movetopoint:cgpointmake(30.0, 100.0)];       [apath addlinetopoint:cgpointmake(200.0, 120.0)];     [apath addlinetopoint:cgpointmake(300, 210)];     [apath addlinetopoint:cgpointmake(300, 420)];     [apath addlinetopoint:cgpointmake(30, 420.0)];     [apath addlinetopoint:cgpointmake(30, 100.0)];      [apath closepath];     [apath fill]; 

any pointers figure out issue code?

first - i've created simple arrow bezier path:

uibezierpath* bezierpath = [uibezierpath bezierpath]; [bezierpath movetopoint: cgpointmake(24.5, 1.5)]; [bezierpath addlinetopoint: cgpointmake(2.5, 14.5)]; [bezierpath addlinetopoint: cgpointmake(24.5, 28.5)]; [bezierpath addlinetopoint: cgpointmake(24.5, 1.5)]; [bezierpath closepath]; [[uicolor blackcolor] setstroke]; bezierpath.linewidth = 1; [bezierpath stroke]; 

enter image description here

then i've drawn simple linear gradient black white:

cgcolorspaceref colorspace = cgcolorspacecreatedevicergb(); cgcontextref context = uigraphicsgetcurrentcontext();  nsarray* simplelineargradientcolors = [nsarray arraywithobjects:                                        (id)[uicolor blackcolor].cgcolor,                                        (id)[uicolor whitecolor].cgcolor, nil]; cgfloat simplelineargradientlocations[] = {0, 1}; cggradientref simplelineargradient = cggradientcreatewithcolors(colorspace, (__bridge cfarrayref)simplelineargradientcolors, simplelineargradientlocations);   // bezier drawing uibezierpath* bezierpath = [uibezierpath bezierpath]; [bezierpath movetopoint: cgpointmake(24.5, 1.5)]; [bezierpath addlinetopoint: cgpointmake(2.5, 14.5)]; [bezierpath addlinetopoint: cgpointmake(24.5, 28.5)]; [bezierpath addlinetopoint: cgpointmake(24.5, 1.5)]; [bezierpath closepath]; cgcontextsavegstate(context); [bezierpath addclip]; cgcontextdrawlineargradient(context, simplelineargradient, cgpointmake(2.5, 15), cgpointmake(24.5, 15), 0); cgcontextrestoregstate(context);  [[uicolor blackcolor] setstroke]; bezierpath.linewidth = 1; [bezierpath stroke];  cggradientrelease(simplelineargradient); cgcolorspacerelease(colorspace); 

that's got:

enter image description here

basically can create linear, radial gradient bunch of settings (locations, colors) , of course should modify code above.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -