How to Implement the gradient effect of drawing a screen and use it as the background template of the program

Source: Internet
Author: User

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];}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.