5

Can someone here please show me how to draw a single dot using UIBezierpath? I am able to draw a line using the UIBezierpath but if I remove my finger and put it back and then remove nothing get drawn on the screen.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint p = [touch locationInView:self];
    [pPath moveToPoint:p];
    [pPath stroke];
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect
{
     [pPath stroke];
}
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
newdev1
  • 279
  • 6
  • 15

2 Answers2

7

Your path doesn't include any line or curve segments to be stroked.

Try this instead:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    CGPoint p = [touches.anyObject locationInView:self];
    static CGFloat const kRadius = 3;
    CGRect rect = CGRectMake(p.x - kRadius, p.y - kRadius, 2 * kRadius, 2 * kRadius);
    pPath = [UIBezierPath bezierPathWithOvalInRect:rect];
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
    [[UIColor blackColor] setFill];
    [pPath fill];
}
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
5

I used this code:

 -(void)handleTap:(UITapGestureRecognizer*)singleTap { 
     //draw dot on screen

     CGPoint tapPoint = [singleTap locationInView:self];
     [bezierPath_ moveToPoint:tapPoint];
     [bezierPath_ addLineToPoint:tapPoint];

     [self setNeedsDisplay]; 
}
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
mirror
  • 345
  • 3
  • 10