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];
}
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];
}
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]; 
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With