title: Draw line between two moveable circles in objective-c (iPad)
body: <p>I'm new to objective-c and am trying to draw a line between moveable circles in Objective-c. I already have code that generates circles. Here is an image that I'd like to create in my app.</p>
  
  <p><a href="http://images.sciencedaily.com/2004/04/040407083832.jpg" rel="nofollow">http://images.sciencedaily.com/2004/04/040407083832.jpg</a></p>
  
  <p>Here's my code.</p>
  
  <p>CircleViewController.m</p>
  
  <pre><code>   - (void)viewDidLoad
     {
       [super viewDidLoad];
       for (int i=0; i&lt;5; i++) {
  
      CGRect circleFrame = CGRectMake(arc4random() % 500, arc4random() % 500, (arc4random() % 200)+50 , (arc4random() % 200)+50);
      CircleView *cirleView = [[CircleView alloc] initWithFrame: circleFrame];
      cirleView.backgroundColor = [UIColor clearColor];
  
      CGFloat hue = ( arc4random() % 256 / 256.0 );  //  0.0 to 1.0
      CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5;  //  0.5 to 1.0, away from white
      CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5;  //  0.5 to 1.0, away from black
      UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
      cirleView.circleColor = color;
      [self.view addSubview:cirleView];
   }
  </code></pre>
  
  <p>}</p>
  
  <p>CircleView.m</p>
  
  <pre><code>   -(void) drawCircle:(CGPoint)p withRadius:(CGFloat)radius inContext:(CGContextRef)contex
     {
         UIGraphicsPushContext(contex);
         CGContextBeginPath(contex);
         CGContextAddArc(contex, p.x, p.y, radius, 0, 2*M_PI, YES);
         CGContextSetLineWidth(contex, 2.0);
         CGContextAddLineToPoint(contex, p.x, p.y);
         CGContextDrawPath(contex, kCGPathFillStroke);
         UIGraphicsPopContext(); 
     }
  
     - (void)drawRect:(CGRect)rect
     {
  
          CGFloat size = self.bounds.size.width/2;
          if(self.bounds.size.height &lt; self.bounds.size.width) size = self.bounds.size.height / 2;
  
          size *= 0.90;
          CGContextRef context = UIGraphicsGetCurrentContext();
          CGContextSetLineWidth(context, 5.0);
  
          [_circleColor setStroke];
          [_circleColor setFill];    
          CGPoint point1;
          point1.x = self.bounds.origin.x + self.bounds.size.width/2;
          point1.y = self.bounds.origin.y + self.bounds.size.height/2;
  
          [self drawCircle:point1 withRadius:size inContext:context];
  
          UITapGestureRecognizer *singleFingerTap =
          [[UITapGestureRecognizer alloc] initWithTarget:self
                                          action:@selector(handleSingleTap:)];
          [self addGestureRecognizer:singleFingerTap];
     }
  </code></pre>
  
  <p>Thank you for your help.</p>