Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Circle.m
- // StressFreeAlarm
- //
- // Created by Rakesh Chander on 19/07/12.
- // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
- //
- #import "Circle.h"
- #import "math.h"
- #define PI 3.14159265358979323846
- static inline float radians(double degrees) { return degrees * PI / 180; }
- @implementation Circle
- -(id)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- // Initialization code
- }
- return self;
- }
- - (void)drawRect:(CGRect)rect
- {
- CGRect parentViewBounds = self.bounds;
- CGFloat x = CGRectGetWidth(parentViewBounds)/2;
- CGFloat y = CGRectGetHeight(parentViewBounds)/2;
- float startPoint=180.0;
- float endPoint=360*(percent/100);
- // 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
- CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor cyanColor] CGColor]));
- CGContextMoveToPoint(ctx, x, y);
- CGContextAddArc(ctx, x, y, 100, radians(startPoint), radians(startPoint+endPoint), 0);
- CGContextClosePath(ctx);
- CGContextFillPath(ctx);
- /* data capacity */
- CGContextSetFillColor(ctx, CGColorGetComponents([[UIColor grayColor] CGColor]));
- CGContextMoveToPoint(ctx, x, y);
- CGContextAddArc(ctx, x, y, 100,radians(startPoint+endPoint), radians(startPoint), 0);
- CGContextClosePath(ctx);
- CGContextFillPath(ctx);
- }
- -(void)setAdaptionPercent:(float)prcent
- {
- percent=prcent;
- [self drawRect:CGRectZero];
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- */
- - (void)dealloc {
- [super dealloc];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment