IPhone uses CG API to draw a pie chart (pie chart)

Source: Internet
Author: User

The core functions are: Cgcontextaddarc (cgcontextref C, CGFloat x, cgfloat y, cgfloat radius, cgfloat startangle, cgfloat endangle, int cloc kwise) * Cgcontextref: Graphics context * x, y: Start drawing coordinates * Radius: RADIUS * startangle, Endangle: Start Radian, End Radian * Clockwise: direction of painting (clockwise, counterclockwise) with this A function can draw any fan, so the pie chart is no longer spoken. #define PI 3.14159265358979323846#define radius 100static inline float radians (double degrees) { return degrees * PI/180; }static inline void DrawArc (Cgcontextref ctx, Cgpoint point, float angle_start, float angle_end, uicolor* color) {Cgconte Xtmovetopoint (CTX, Point.x, POINT.Y); Cgcontextsetfillcolor (CTX, cgcolorgetcomponents ([color Cgcolor])); Cgcontextaddarc (CTX, Point.x, Point.y, radius, Angle_start, angle_end, 0); Cgcontextclosepath (CTX); Cgcontextfillpath (CTX); }-(void) DrawRect: (cgrect) rect {cgcontextref CTX = Uigraphicsgetcurrentcontext (); Cgcontextclearrect (CTX, rect); float Angle_start = radians (0.0); float angle_end = radians (121.0); DrawArc (CTX, Self.center, Angle_start, Angle_end, [Uicolor Yellowcolor]);Angle_start = Angle_end; Angle_end = radians (228.0); DrawArc (CTX, Self.center, Angle_start, Angle_end, [Uicolor Greencolor]); Angle_start = Angle_end; Angle_end = radians (260); DrawArc (CTX, Self.center, Angle_start, Angle_end, [Uicolor Orangecolor]); Angle_start = Angle_end; Angle_end = radians (360); DrawArc (CTX, Self.center, Angle_start, Angle_end, [Uicolor Purplecolor]);}

IPhone uses CG API to draw a pie chart (pie chart)

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.