objective c - iPhone - Help with CGGradientCreateWithColorComponents and creating gradient as per screenshot -
i trying apply same gradient per screen shot below using cggradientcreatewithcolorcomponents
.
this i'm using @ moment, it's not quite right , i'm after better way of trying guess these values. i'd know how determine these values code grabbed tutorial, didn't explain @ in terms of components are.
cgcolorspaceref mycolorspace = cgcolorspacecreatedevicergb(); cgfloat components[8] = { 1, 1, 1, 1, 0.866, 0.866, 0.866, 1 }; cgfloat locations[2] = { 0.0, 1.0 }; cggradientref mygradient = cggradientcreatewithcolorcomponents(mycolorspace, components, locations, 2);
i've played around , got picture:
with colors:
static const cgfloat colors [] = { 0.894, 0.894, 0.894, 1.0, 0.694, 0.694, 0.694, 1.0 };
using piece of code:
- (void) drawrect:(cgrect)rect { cgcolorspaceref basespace = cgcolorspacecreatedevicergb(); cggradientref gradient = cggradientcreatewithcolorcomponents(basespace, colors, null, 2); cgcolorspacerelease(basespace), basespace = null; cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextclearrect(context, rect); cgcontextsavegstate(context); cgpoint startpoint = cgpointmake(cgrectgetmidx(rect), cgrectgetminy(rect)); cgpoint endpoint = cgpointmake(cgrectgetmidx(rect), cgrectgetmaxy(rect)); cgcontextclip(context); cgcontextdrawlineargradient(context, gradient, startpoint, endpoint, 0); cggradientrelease(gradient), gradient = null; cgcontextrestoregstate(context); [super drawrect:rect]; }
i dont know if it's close enough.
Comments
Post a Comment