Question

Within my app, I use drawRect to draw some text within a UIImage. It writes multiple things in multiple places.. Later, I try to erase some of the text by using

CGContextSetBlendMode(context, kCGBlendModeClear);

CGPoint daPoint = CGPointMake(second.x + 20, second.y + 20);

NSDictionary *textAttributes = @{ NSFontAttributeName: [UIFont boldSystemFontOfSize:25.0],
                                                  NSForegroundColorAttributeName:   [UIColor clearColor] };

[textString drawAtPoint:daPoint withAttributes:textAttributes];

This works almost perfectly, except there is a small thin stroke left over from the text. I use the same code to draw the text, as I do to erase, except when i'm drawing I use kCGBlendModeNormal. How would I get rid of it completely? Can I draw a box and fill it using kCGBlendModeClear? This is what it looks like currently before erasing:

enter image description here

After erasing:

enter image description here

Was it helpful?

Solution

I would get the bounding rect of the text and then call CGContextClearRect and then fill with the background color if you think that "erasing" the text is really necessary. If you simply "redraw" your rect, that might be another way to solve this problem.

Here's how to get that bounding box for clearing:

CGSize textSize = [textString sizeWithAttributes:textAttributes];
CGRect textFrame = CGRectMake(daPoint.x, daPoint.y, textSize.width, textSize.height);

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top