1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 // Do any additional setup after loading the view, typically from a nib. 4 5 UIImage *image = [UIImage imageNamed:@"卡哇伊"]; 6 7 //生成图片. 8 //size:开开启一个多大图片上下文. 9 //opaque:不透度 10 //scale:0 11 //开启跟图片相同的大小上下文. 12 UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0); 13 //把图片给绘制图片上下文. 14 [image drawAtPoint:CGPointZero]; 15 //绘制文字 16 NSString *str = @"小码哥"; 17 [str drawAtPoint:CGPointZero withAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:20]}]; 18 //生成图片 19 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 20 //手动关闭上下文 21 UIGraphicsEndImageContext(); 22 23 self.imageV.image = newImage; 24 25 26 }
浙公网安备 33010602011771号