創建兩個UIImage
對象,一個UILabel
對象,然後使用drawInRect:
方法
//create image 1
UIImage *img1 = [UIImage imageNamed:@"image1.png"];
//create image 2
UIImage *img2 = [UIImage imageNamed:@"image2.png"];
// create label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50,50)];
//set you label text
[label setText:@"Hello"];
// use UIGraphicsBeginImageContext() to draw them on top of each other
//start drawing
UIGraphicsBeginImageContext(img1.size);
//draw image1
[img1 drawInRect:CGRectMake(0, 0, img1.size.width, img1.size.height)];
//draw image2
[img2 drawInRect:CGRectMake((img1.size.width - img2.size.width) /2, (img1.size.height- img2.size.height)/2, img2.size.width, img2.size.height)];
//draw label
[label drawTextInRect:CGRectMake((img1.size.width - label.frame.size.width)/2, (img1.size.height - label.frame.size.height)/2, label.frame.size.width, label.frame.size.height)];
//get the final image
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
的resultImage
這是UIImage
包含所有圖像和標籤作爲一個圖像。之後,你可以將它保存在你想要的地方。
希望有幫助...
我應該如何繪製UITextView?沒有「drawInRect」這樣的函數( –