Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 27th, 2012  |  syntax: None  |  size: 2.25 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. drawRect not responding
  2. -(void)prepareVertex:(int)noOfVertex
  3. {
  4.   polygonPoint=[NSMutableArray arrayWithCapacity:noOfVertex];
  5.   for(int i=0;i<noOfVertex;i++)
  6.   {
  7.     CGPoint point=CGPointMake(sin((2*M_PI)*i/noOfVertex),(cos(2*M_PI)*i/noOfVertex));
  8.     [polygonPoint addObject:[NSValue valueWithCGPoint:point]];
  9.     NSValue *tempVal=[polygonPoint objectAtIndex:i];
  10.     CGPoint tempPoint=[tempVal CGPointValue];
  11.     NSLog(@"%f,%f",tempPoint.x,tempPoint.y);
  12.   }
  13.  
  14. }
  15.  
  16. - (void)drawRect:(CGRect)rect
  17. {
  18.  
  19.   [self prepareVertex:5];    
  20.   for (int i=0; i<5; i++) {
  21.     NSValue *tempVal=[polygonPoint objectAtIndex:i];
  22.     CGPoint tempPoint=[tempVal CGPointValue];
  23.   }
  24.  
  25.  
  26.   CGContextRef context=UIGraphicsGetCurrentContext();
  27.   CGContextSetLineWidth(context, 5);
  28.   CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
  29.   CGContextMoveToPoint(context, [[polygonPoint objectAtIndex:0] CGPointValue].x, [[polygonPoint objectAtIndex:0] CGPointValue].x);
  30.   for (int i=1; i<5; i++) {
  31.     CGPoint point=[[polygonPoint objectAtIndex:i] CGPointValue];
  32.     CGContextAddLineToPoint(context,point.x, point.y);
  33.   }
  34.   CGContextStrokePath(context);
  35. }
  36.        
  37. - (void)drawRect:(CGRect)rect {
  38.     [self prepareVertex:5];    
  39.  
  40.     CGContextRef context=UIGraphicsGetCurrentContext();
  41.     CGContextSetLineWidth(context, 5);
  42.     CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
  43.  
  44.     CGFloat x = self.center.x + self.bounds.size.width * 0.5 * [[polygonPoint objectAtIndex:0] CGPointValue].x;
  45.     CGFloat y = self.center.y + self.bounds.size.height * 0.5 * [[polygonPoint objectAtIndex:0] CGPointValue].y;
  46.     NSLog(@"Point %f/%f", x, y);
  47.     CGContextMoveToPoint(context, x, y);
  48.  
  49.     for (int i=1; i<5; i++) {
  50.         CGPoint point=[[polygonPoint objectAtIndex:i] CGPointValue];
  51.         x = self.center.x + self.bounds.size.width * 0.5 * point.x;
  52.         y = self.center.y + self.bounds.size.height * 0.5 * point.y;
  53.         NSLog(@"Point %f/%f", x, y);
  54.         CGContextAddLineToPoint(context, x, y);
  55.     };
  56.     CGContextStrokePath(context);
  57. }
  58.        
  59. CGPoint point=CGPointMake(sin((2*M_PI)*i/noOfVertex),(cos(2*M_PI)*i/noOfVertex));
  60.        
  61. CGFloat x = centerPoint.x + radius * sin(2*M_PI*i/noOfVertex);
  62. CGFloat y = centerPoint.y + radius * cos(2*M_PI*i/noOfVertex);
  63. CGPoint point = CGPointMake(x, y);