objective c - In iOS Development, using Core Graphics and/or Quartz 2D, how can I draw a circle filled with a gradient in such a manner that it looks like a sphere? -



objective c - In iOS Development, using Core Graphics and/or Quartz 2D, how can I draw a circle filled with a gradient in such a manner that it looks like a sphere? -

so far have looked @ using cgcontextdrawlineargradient() , cgcontextdrawradialgradient(), however, former can't figure out how create gradient sphere, , latter, can't figure out how create gradient shape of sphere, because every time try, turns out in shape of total cylinder instead of sphere.

the code using current draw 2d circle shown below. utilize gradient or other method possible using core graphics and/or quartz 2d fill circle in manner makes sphere.

current code drawing circle:

cgcontextref ctx = uigraphicsgetcurrentcontext(); float x = 20.0; float y = 20.0; float radius = 12.5; cgcontextfillellipseinrect(ctx, cgrectmake(x, y, radius, radius);

p.s. - above code works supposed to, in case there errors, they're errors while typing question, not while typing code actual file.

i believe effect looking for:

this created using radial gradient. gradient starts radius of 0 , ends radius of size of circle. center point of start must within circle created end, or cone shape instead. here code used create image (a couple parts need translated ios before utilize it):

cgcontextref ctxt = [[nsgraphicscontext currentcontext] graphicsport]; cggradientref gradient; cgcolorspaceref colorspace; cgfloat locations[] = {0.0,1.0}; cgfloat components[] = { 0.5,1.0,1.0,1.0, 0.25,0.5,0.5,1.0 }; colorspace = cgcolorspacecreatewithname(kcgcolorspacegenericrgb); gradient = cggradientcreatewithcolorcomponents(colorspace,components,locations, sizeof(locations)/sizeof(cgfloat)); cgpoint start = {70.0,130.0}, end = {100.0,100.0}; cgfloat startradius = 0.0, endradius = 90.0; cgcontextdrawradialgradient(ctxt,gradient,start,startradius,end,endradius,0); cggradientrelease(gradient); cgcolorspacerelease(colorspace);

ios objective-c geometry core-graphics quartz-2d

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -