Erase line drawing with UIBezierPath

Did a simple application for line drawing with UIBezierPath, but now need a way to erase the line drawn with UIBezierPath. Is there a way to implement eraser feature for removing the line painting?

Answers


If you are using an image as background then you can set the same image as brush pattern to draw the bezierpath it will virtually give you the eraser effect. It works for me. :)

    brushPattern=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"image.jpg"]];
    // Here image.jpg is you background image

if(erase)
{
    [myPath strokeWithBlendMode:kCGBlendModeClear alpha:1.0f];
}
else
{
    [myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0f];
}

An eraser effectively draws a line that's the same color as the background atop every path that's been drawn thus far. You might need to note that it's an eraser line somewhere so that you can update the eraser line's stroke color if the background color changes, otherwise you lose the illusion of erasure.


Based on your comments on Jeremy's answer, it seems like you're trying to do dashed lines. Have you tried using setLineDash:count:phase:

UIBezierPath *path = [UIBezierPath new];
CGFloat dashArray[3];
dashArray[0] = 8;
dashArray[1] = 3;
dashArray[2] = 8;
[path setLineDash:dashArray count:dashCount phase: 0.0];

Apple has sample code here: http://developer.apple.com/library/mac/#samplecode/BezierPathLab/Introduction/Intro.html


Need Your Help

IoC dependency Injection determining the class from Ajax

.net dependency-injection inversion-of-control

I am an IoC beginner, I am facing a serious problem with implementing the IoC dependency injection.

Cache Hit or Miss?

caching assembly computer-architecture

Can ANYONE solve where these instructions will be hit or miss in cache?