【发布时间】:2018-10-18 03:33:59
【问题描述】:
我正在尝试绘制一个 UIView 并从中删除文本以产生类似于此的效果:
到目前为止,我还没有找到一种让文本充当橡皮擦的方法。这就是我所在的地方:
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(c, [UIColor whiteColor].CGColor);
CGContextFillRect(c, self.bounds);
CGContextSetBlendMode(c, kCGBlendModeClear);
CGContextSetTextDrawingMode(c, kCGTextFill);
CGContextSetFont(c, CGFontCreateWithFontName(CFStringCreateWithCString(NULL, "HelveticaNeue-Bold", kCFStringEncodingUTF8)));
CGContextSetFontSize(c, 18.0);
UIGraphicsPushContext(c);
[_text drawInRect:self.bounds
withAttributes:nil];
UIGraphicsPopContext();
我希望CGContextSetBlendMode(c, kCGBlendModeClear); 能让文本充当橡皮擦,但到目前为止,我还没有运气。
我也有使用 UILabel 作为 maskView 的想法,但我不知道如何反转它以便将文本视为负空间。我能找到的关于反转蒙版的唯一问题是反转 CAShapeLayers 或 UIImage。
【问题讨论】:
-
如何对标签进行截图、反转 alpha 并将生成的图像用作遮罩?
标签: ios objective-c uiview core-graphics