Chapter 5 concentric circles with color

Source: Internet
Author: User

1. Override drwarect

-(Void) drawrect :( cgrect) rect {cgrect bounds = self. bounds; cgpoint center; center. X = bounds. origin. X + bounds. size. width/2.0; center. y = bounds. origin. Y + bounds. size. height/2.0; float maxradius = max (bounds. size. width, bounds. size. height );
// Circle uibezierpath * Path = [[uibezierpath alloc] init]; for (float currentradius = maxradius; currentradius> 0; currentradius-= 20) {[path movetopoint: cgpointmake (center. X + currentradius, center. y)]; [path addarcwithcenter: center radius: currentradius startangle: 0.0 endangle: m_pi * 2.0 clockwise: Yes];} path. linewidth = 10; // configure the drawing color of light gray [self. circlecolor setstroke]; [path stroke];/* cgcontextref currentcontext = uigraphicsgetcurrentcontext (); cgcontextsavegstate (currentcontext); [path addclip]; // gradient triangle cgfloat location [2] = {0.0, 1.0}; cgfloat components [8] = {1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0 }; cgcolorspaceref colorspace = cgcolorspacecreatedevicergb (); cggradientref gradient = cggradientcreatewithcolorcomponents (colorspace, components, location, 2); cgpoint startpoint = cgpointmake (rect. size. width/2.0, rect. size. high/4.0); cgpoint endpoint = cgpointmake (rect. size. width/2.0, rect. size. height * 0.75); values (currentcontext, gradient, startpoint, endpoint, 0); cgcolorspacerelease (colorspace); cggradientrelease (gradient); // Add shadow of image cgcontextsetshadow (currentcontext, cgsizemake (4.0, 7.0), 3); // draw stuff here, it will appear with a shadow // Add logo image uiimage * logoimage = [uiimage imagenamed: @ "logo.png"]; cgrect logorect = cgrectmake (rect. size. width/4.0, rect. size. height/4.0, rect. size. width/2.0, rect. size. height/2.0); [logoimage drawinrect: logorect]; cgcontextrestoregstate (currentcontext); // draw stuff here, it will apear with no shadow; cgcontextrelease (currentcontext );*/}

2. Override touchesbegin: withevent

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{//    NSLog(@"%@ was touched", self);        // Get 3 random numbers between 0 and 1    float red = (arc4random() % 100) / 100.0;    float blue = (arc4random() % 100) / 100.0;    float green = (arc4random() % 100) / 100.0;        UIColor *randomColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];    self.circleColor = randomColor;}

Iii. redrawing View

[self setNeedsDisplay];

 

Chapter 5 concentric circles with color

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.