【发布时间】:2015-10-14 23:32:51
【问题描述】:
我想以编程方式在图像上添加文本,但我似乎找不到如何做到这一点。我在这里找到了one 解决方案,但是很多东西都被弃用了,所以它不起作用......
请帮忙!
编辑:
这是我的代码:
UIImage *backgroundImage = image;
NSMutableDictionary *stringAttributes = [NSMutableDictionary dictionary];
[stringAttributes setObject: [UIFont fontWithName:@"Helvetica" size:20] forKey: NSFontAttributeName];
[stringAttributes setObject: [UIColor whiteColor] forKey: NSForegroundColorAttributeName];
[stringAttributes setObject: [NSNumber numberWithFloat: 2.0] forKey: NSStrokeWidthAttributeName];
[stringAttributes setObject: [UIColor blackColor] forKey: NSStrokeColorAttributeName];
[backgroundImage drawInRect:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)];
NSString *myString = [NSString stringWithFormat:@"Yolo"];
[myString drawInRect:CGRectMake(0, 0, 200, 50) withAttributes:stringAttributes];
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.imageView.image = result;
新编辑:
我想澄清一些事情以更好地理解这个问题。我的应用程序允许用户通过短信或电子邮件发送他们自己拍摄的照片,我想在照片上添加一些预先编写的字符串文本。
所以我的问题是:如何从字符串中获取文本到照片上?
【问题讨论】:
标签: ios objective-c