我有一个自定义的UIImageView类,它有以下方法:
- (void) cutOutText:(NSString*)stringToStencil;
我希望该方法以一种从图像中剪切文本的方式来屏蔽图像。该方法的结果是在中心具有透明文本的不透明图像。到目前为止,我有以下内容:
NSMutableParagraphStyle *textStyle = [NSMutableParagraphStyle new];
[textStyle setAlignment:NSTextAlignmentCenter];
NSAttributedString *initialsString = [[NSAttributedString alloc] initWithString: stringToStencil,attributes:@{NSFontAttributeName:_initialsFont, NSForegroundColorAttributeName:_initialsTextColor, NSParagraphStyleAttributeName: textStyle}];
UIGraphicsBeginImageContextWithOptions(self.image.size, NO, 0.0f);
[self.image drawAtPoint:CGPointMake(0, 0)];
CGFloat fontHeight = _initialsFont.lineHeight;
CGFloat yOffset = (self.frame.size.height - fontHeight) / 2.0;
[initialsString drawInRect:CGRectMake(self.frame.origin.x, yOffset, self.frame.size.width, self.frame.size.height)];
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
self.image = result;
然而,这只是将文本打印到图像上。如何创建蒙版并从图像中删除文本呢?
由于
d