如何使用drawAtPoint()覆盖UIImage?

时间:2012-09-21 00:47:04

标签: objective-c uiimage

以下代码在图像上绘制一些文字:

UIGraphicsBeginImageContext(image.size);
[image drawAtPoint:CGPointZero];

NSString *stamp = @"Internal Use Only";
[stamp drawAtPoint:CGPointMake(10, 10) withFont:[UIFont systemFontOfSize:32]];

UIImage *stampedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

如果使用不同的字符串再次执行代码,则两个字符串组合在一起并且不易读。我怎么能这样做drawAtPoint()覆盖前一个字符串?

2 个答案:

答案 0 :(得分:0)

每次要在其上绘制文本时,都必须复制原始图像。换句话说,您必须保留图像的原始版本。

答案 1 :(得分:0)

我能够通过渲染UITextView来完成这项工作。这些知道如何通过他们的图层属性绘制自己,并可以显示多行(添加奖金!):

CGContextRef context = UIGraphicsGetCurrentContext();
NSString *stamp = @"Internal Use Only";
CGRect frame = CGRectMake(0, 0, 120, 80);
textview.frame = frame;
textview.text = stamp;
textview.font = [UIFont systemFontOfSize:32];
[textview.layer renderInContext:context];