I have an iPhone application and I need to implement the following method:
+(UITextView *)textView:(UITextView *) withCuttedRect:(CGRect)r
This method must cut (fill with [UIColor clearColor]) the rect r from UITextView and return UITextView object.
The user will see the view behind UITextView from the cutted holes.
How can it be done?
When you would have something like:
you actually can simply access the textview’s layer from core animation with
What you then can to is set a mask for clipping. These masks work the following way: you generally draw a black shape, and that stays the same, the rest will be clipped (ok, you actually can also do some things on the alpha channel but roughly that is it).
So you need a black rectangle as a mask, with a rectangle within the rectangle which is free. for that you can approximately do
The code above is also disused by Crop a CAShapeLayer retrieving the external path
The idea why that filling works that way is nicely explained in Quartz 2D Programming Guide in the section “Filling a Path”