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