Sometimes you need
Bgengine. h
# Import <uikit/uikit. h> @ interface bgview: uiview {cggradientref gradient;} @ end
Bgengine. m
# Import "bgengine. H" @ implementation bgview-(ID) initwithframe :( cgrect) frame {self = [Super initwithframe: frame]; If (self! = Nil) {cgcolorspaceref RGB = cgcolorspacecreatedevicergb (); cgfloat colors [] = {243.0/255.0, 181.0/255.0, 206.0/255.0, 1.00/207.0, 255.0/170.0, 255.0, 185.0/255.0, 1.00,}; gradient = cggradientcreatewithcolorcomponents (RGB, colors, null, sizeof (colors)/(sizeof (colors [0]) * 4 )); cgcolorspacerelease (RGB);} return self;}-(void) dealloc {cfrelease (gradient); [Super dealloc];} // returns an appropriate starting point for the demonstration of a linear gradientcgpoint demolgstart (cgrect bounds) {return cgpointmake (bounds. origin. x, bounds. origin. y);} // returns an appropriate ending point for the demonstration of a linear gradientcgpoint demolgend (cgrect bounds) {return cgpointmake (bounds. origin. x, bounds. origin. Y + bounds. size. height) ;}- (void) drawrect :( cgrect) rect {cgpoint start, end; cgcontextref context = histogram (); cgcontextsavegstate (context); cgcontextcliptorect (context, rect ); start = demolgstart (rect); End = demolgend (rect); cgcontextdrawlineargradient (context, gradient, start, end, 0); cgcontextrestoregstate (context);} @ end
Add the following in the veiwdidload function of each viewcontroller to be used:Code:
When used:-(void) resetbgview {cgrect appframe = [uiscreen mainscreen]. applicationframe; cgrect bgframe = cgrectmake (0, 44 + 20, appframe. size. width, appframe. size. height-44-48); // determines bgview * bgview = [[bgview alloc] initwithframe: bgframe] Based on Century requirements; [Window insertsubview: bgview atindex: 0]; [bgview release];}