rotating a circle in UIView?

0 votes
asked Jun 11, 2010 by senthil-freelancer

I want to draw a circle in drawRect through a context like a pie chart thorugh UITouch (took from a tutorial)? I have given the code as follows, how can I rotate? Any help please?

#define PI 3.14159265358979323846
#define snapshot_start 360
#define snapshot_finish 360
static inline float radians(double degrees) { return degrees * PI / 180; }

   - (void)drawRect:(CGRect)rect 
// Drawing code
CGRect parentViewBounds = self.bounds;
CGFloat x = CGRectGetWidth(parentViewBounds)/2;
CGFloat y = CGRectGetHeight(parentViewBounds)*0.55;

// Get the graphics context and clear it
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect);

// define stroke color
CGContextSetRGBStrokeColor(ctx, 1, 1, 1, 1.0);

// define line width
CGContextSetLineWidth(ctx, 4.0);

// need some values to draw pie charts

double snapshotCapacity =20;
double rawCapacity = 100;
double systemCapacity = 1;

int offset = 5;
double pie1_start = 315.0;
double pie1_finish = snapshotCapacity *360.0/rawCapacity;
double system_finish = systemCapacity*360.0/rawCapacity;

CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor greenColor] CGColor]));
CGContextMoveToPoint(ctx, x+2*offset, y);
CGContextAddArc(ctx, x+2*offset, y, 100,  radians(snapshot_start), radians(snapshot_start+snapshot_finish), 0);

// system capacity 
CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor colorWithRed:15 green:165/255 blue:0 alpha:1 ] CGColor]));
CGContextMoveToPoint(ctx, x+offset,y);
CGContextAddArc(ctx, x+offset, y, 100,  radians(snapshot_start+snapshot_finish+offset), radians(snapshot_start+snapshot_finish+system_finish), 0);

/* data capacity */
CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor colorWithRed:99/255 green:184/255 blue:255/255 alpha:1 ] CGColor]));
CGContextMoveToPoint(ctx, x, y);
CGContextAddArc(ctx, x, y, 100,  radians(snapshot_start+snapshot_finish+system_finish+offset), radians(snapshot_start), 0);

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter