- (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