Guest User

Untitled

a guest
Aug 17th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. //
  2. // Circle.m
  3. // StressFreeAlarm
  4. //
  5. // Created by Rakesh Chander on 19/07/12.
  6. // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import "Circle.h"
  10. #import "math.h"
  11.  
  12. #define PI 3.14159265358979323846
  13. static inline float radians(double degrees) { return degrees * PI / 180; }
  14.  
  15. @implementation Circle
  16.  
  17.  
  18. -(id)initWithFrame:(CGRect)frame {
  19. if (self = [super initWithFrame:frame]) {
  20. // Initialization code
  21. }
  22. return self;
  23. }
  24.  
  25. - (void)drawRect:(CGRect)rect
  26. {
  27. CGRect parentViewBounds = self.bounds;
  28. CGFloat x = CGRectGetWidth(parentViewBounds)/2;
  29. CGFloat y = CGRectGetHeight(parentViewBounds)/2;
  30.  
  31. float startPoint=180.0;
  32. float endPoint=360*(percent/100);
  33.  
  34. // Get the graphics context and clear it
  35. CGContextRef ctx = UIGraphicsGetCurrentContext();
  36. CGContextClearRect(ctx, rect);
  37.  
  38. // define stroke color
  39. CGContextSetRGBStrokeColor(ctx, 1, 1, 1, 1.0);
  40.  
  41. // define line width
  42. CGContextSetLineWidth(ctx, 4.0);
  43.  
  44. // need some values to draw pie charts
  45.  
  46. CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor cyanColor] CGColor]));
  47. CGContextMoveToPoint(ctx, x, y);
  48. CGContextAddArc(ctx, x, y, 100, radians(startPoint), radians(startPoint+endPoint), 0);
  49. CGContextClosePath(ctx);
  50. CGContextFillPath(ctx);
  51.  
  52. /* data capacity */
  53. CGContextSetFillColor(ctx, CGColorGetComponents([[UIColor grayColor] CGColor]));
  54. CGContextMoveToPoint(ctx, x, y);
  55. CGContextAddArc(ctx, x, y, 100,radians(startPoint+endPoint), radians(startPoint), 0);
  56. CGContextClosePath(ctx);
  57. CGContextFillPath(ctx);
  58. }
  59.  
  60. -(void)setAdaptionPercent:(float)prcent
  61. {
  62. percent=prcent;
  63. [self drawRect:CGRectZero];
  64. }
  65.  
  66. /*
  67. // Only override drawRect: if you perform custom drawing.
  68. // An empty implementation adversely affects performance during animation.
  69. */
  70.  
  71. - (void)dealloc {
  72. [super dealloc];
  73. }
  74.  
  75. @end
Advertisement
Add Comment
Please, Sign In to add comment