- (void)viewDidLoad {
[super viewDidLoad];
//开启图片上下文,画图片
UIImage *image = [UIImage imageNamed:@"黄人"];
UIGraphicsBeginImageContextWithOptions(image.size, NO, 1);
[image drawAtPoint:CGPointMake(0, 0)];
//画文字
NSString *str = @"@360百度";
/*注意:同时设置了空心的两个属性 NSStrokeWidthAttributeName 和
NSStrokeColorAttributeName (需两个同时设置才有效),
文字前景色 NSForegroundColorAttributeName 就无效果了*/
[str drawAtPoint:CGPointZero withAttributes:@{NSStrokeWidthAttributeName:@2.0,
NSStrokeColorAttributeName:[UIColor grayColor],
NSFontAttributeName:[UIFont systemFontOfSize:50]}];
//导出图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
//保存到桌面
[UIImagePNGRepresentation(newImage) writeToFile:@"/Users/mengmei/Desktop/黄人.png" atomically:YES];
self.imageView.image = newImage; //显示到imageView
//关闭上下文
UIGraphicsEndImageContext();
}
效果###
黄人.png