iphone - Add a simple CGGradient to UINavigationBar -
possible duplicate:
uinavigationbar gradient details
i looked around web haven't found clear example. have no experience cggradient need simple thing: want add gradient navigationbar of navigationcontroller, gradient should linear, top bottom. want start color : (88.0, 38.0, 40.0) , end color (50.0 15.0 16.0). please give me example of how add gradient navigation bar?
thank
adjust color or supply image if want
// #lighter r,g,b,a #darker r,g,b,a #define main_color_components { 0.153, 0.306, 0.553, 1.0, 0.122, 0.247, 0.482, 1.0 } #define light_color_components { 0.478, 0.573, 0.725, 1.0, 0.216, 0.357, 0.584, 1.0 } @implementation uinavigationbar (uinavigationbarcategory) - (void)drawrect:(cgrect)rect { if (imageready) { uiimage *img = [uiimage imagenamed: @"navigation_background.png"]; [img drawinrect:cgrectmake(0, 0, self.frame.size.width, self.frame.size.height)]; } else { // render instead. // need adjust main_color_components , light_color_components match app // emulate tint colored bar cgcontextref context = uigraphicsgetcurrentcontext(); cgfloat locations[2] = { 0.0, 1.0 }; cgcolorspaceref mycolorspace = cgcolorspacecreatedevicergb(); cgfloat topcomponents[8] = light_color_components; cggradientref topgradient = cggradientcreatewithcolorcomponents(mycolorspace, topcomponents, locations, 2); cgcontextdrawlineargradient(context, topgradient, cgpointmake(0, 0), cgpointmake(0,self.frame.size.height/2), 0); cggradientrelease(topgradient); cgfloat botcomponents[8] = main_color_components; cggradientref botgradient = cggradientcreatewithcolorcomponents(mycolorspace, botcomponents, locations, 2); cgcontextdrawlineargradient(context, botgradient, cgpointmake(0,self.frame.size.height/2), cgpointmake(0, self.frame.size.height), 0); cggradientrelease(botgradient); cgcolorspacerelease(mycolorspace); // top line cgcontextsetrgbstrokecolor(context, 1, 1, 1, 1.0); cgcontextmovetopoint(context, 0, 0); cgcontextaddlinetopoint(context, self.frame.size.width, 0); cgcontextstrokepath(context); // bottom line cgcontextsetrgbstrokecolor(context, 0, 0, 0, 1.0); cgcontextmovetopoint(context, 0, self.frame.size.height); cgcontextaddlinetopoint(context, self.frame.size.width, self.frame.size.height); cgcontextstrokepath(context); } }
Comments
Post a Comment