IOS development and ios development tutorial

Source: Internet
Author: User

IOS development and ios development tutorial
Quartz2D

-(Void) drawRect :( CGRect) rect {// 1. context CGContextRef ctx = UIGraphicsGetCurrentContext (); // 2. body drawBody (ctx, rect); // 3. mouth (SMILE) drawMouth (ctx, rect); // 4. draw eye drawEyes (ctx, rect);}/*** eye */void drawEyes (CGContextRef ctx, CGRect rect) {// 1. black Strap CGFloat startX = rect. size. width * 0.5-Radius; CGFloat startY = TopY; CGContextMoveToPoint (ctx, startX, startY); CGFloat endX = startX + 2 * Radius; CGFloat endY = startY; CGContextAddLineToPoint (ctx, endX, endY); CGContextSetLineWidth (ctx, 15); [[UIColor blackColor] set]; // draw the CGContextStrokePath (ctx) line; // 2. outermost frame [ZLColor (61, 62, 66) set]; CGFloat kuangRadius = Radius * 0.4; CGFloat kuangY = startY; CGFloat kuangX = rect. size. width * 0.5-kuangRadius; CGContextAddArc (ctx, kuangX, kuangY, kuangRadius, 0, M_PI * 2, 0); CGContextFillPath (ctx); [ZLColor (61, 62, 66) set]; CGFloat kuangRadius1 = Radius * 0.4; CGFloat kuangY1 = startY; CGFloat kuangX1 = rect. size. width * 0.5 + kuangRadius; CGContextAddArc (ctx, kuangX1, kuangY1, kuangRadius1, 0, M_PI * 2, 0); CGContextFillPath (ctx); // 3. white Box [[UIColor whiteColor] set]; CGFloat whiteRadius = kuangRadius * 0.7; CGFloat whiteX = kuangX; CGFloat whiteY = kuangY; ctx, whiteX, whiteY, whiteRadius, 0, m_PI * 2, 0); CGContextFillPath (ctx); [[UIColor whiteColor] set]; CGFloat whiteRadius1 = kuangRadius * 0.7; CGFloat whiteX1 = kuangX + 2 * kuangRadius; CGFloat whiteY1 = kuangY; CGContextAddArc (ctx, whiteX1, whiteY1, whiteRadius1, 0, M_PI * 2, 0); CGContextFillPath (ctx); // 4. brown eyeball [ZLColor (76, 23, 13) set]; CGFloat brownRadius = kuangRadius * 0.4; CGFloat brownX = kuangX + 2 * kuangRadius-6; CGFloat brownY = kuangY; CGContextAddArc (ctx, brownX, brownY, brownRadius, 0, M_PI * 2, 0); CGContextFillPath (ctx); [ZLColor (76, 23, 13) set]; CGFloat brownRadius1 = kuangRadius * 0.4; CGFloat brownX1 = kuangX + 6; CGFloat brownY1 = kuangY; CGContextAddArc (ctx, brownX1, brownY1, struct, 0, M_PI * 2, 0); CGContextFillPath (ctx); // 5. black pupil [[UIColor blackColor] set]; CGFloat blackRadius = kuangRadius * 0.2; CGFloat blackX = kuangX + 2 * kuangRadius-6; CGFloat blackY = kuangY; CGContextAddArc (ctx, blackX, blackY, blackRadius, 0, M_PI * 2, 0); CGContextFillPath (ctx); [UIColor blackColor] set]; CGFloat blackRadius1 = kuangRadius * 0.2; CGFloat blackX1 = kuangX + 6; CGFloat blackY1 = kuangY; CGContextAddArc (ctx, blackX1, blackY1, blackRadius1, 0, M_PI * 2, 0); CGContextFillPath (ctx); // 6. white reflection [[UIColor whiteColor] set]; CGFloat lightRadius = kuangRadius * 0.1; CGFloat lightX = kuangX + 2 * kuangRadius; CGFloat lightY = kuangY; CGContextAddArc (ctx, lightX, lightY, lightRadius, 0, M_PI * 2, 0); CGContextFillPath (ctx); [[UIColor whiteColor] set]; CGFloat lightRadius1 = kuangRadius * 0.1; CGFloat lightX1 = kuangX + 2 * kuangRadius-45; CGFloat lightY1 = kuangY; CGContextAddArc (ctx, lightX1, lightY1, lightRadius1, 0, M_PI * 2, 0); CGContextFillPath (ctx );} /*** nozzle */void drawMouth (CGContextRef ctx, CGRect rect) {// Control Point CGFloat controlX = rect. size. width * 0.5; CGFloat controlY = rect. size. height * 0.4; // current vertex CGFloat Margat = 20; CGFloat marginY = 10; CGFloat currentX = controlX-marginX; CGFloat currentY = controlY-marginY; CGContextMoveToPoint (ctx, currentX, currentY); // end point CGFloat endX = controlX + margdy; CGFloat endY = currentY; // CGContextAddQuadCurveToPoint (ctx, controlX, controlY, endX, endY ); // set the color [[UIColor blackColor] set]; // render CGContextStrokePath (ctx);}/*** draw the body */void drawBody (CGContextRef ctx, CGRect rect) {// CGFloat topX = rect. size. width * 0.5; CGFloat topY = TopY; CGFloat topRadius = Radius; CGContextAddArc (ctx, topX, topY, topRadius, 0, M_PI, 1 ); // extend CGFloat middleX = topX-topRadius; CGFloat middleH = 100; // The height of the intermediate body CGFloat middleY = topY + middleH; CGContextAddLineToPoint (ctx, middleX, middleY ); // CGFloat bottomX = topX; CGFloat bottomY = middleY; CGFloat bottomRadius = topRadius; substring (ctx, bottomX, bottomY, bottomRadius, M_PI, 0, 1 ); // merge path CGContextClosePath (ctx); // set the color [ZLColor (252,218, 0) set]; // use the fill method to draw the previous path CGContextFillPath (ctx );}


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.