我试图通过根据给定字符串选择随机图像来制作单个图像。为此,我正在编写以下代码,它完全正常:
int count=self.txtFld.text.length;
self.imgView3.image=nil;
UIButton *btn=(UIButton*)sender;
if(btn.tag==1)
{
NSLog(@"Blackaddr Btn Clicked..");
int i=0;
while (i<count) {
UIImage *img=self.imgView1.image;
CGSize size = CGSizeMake(self.imgView3.image.size.width+img.size.width-10, img.size.height);
UIGraphicsBeginImageContext(size);
[self.imgView3.image drawInRect:CGRectMake(0, 0, self.imgView3.image.size.width, self.imgView3.image.size.height)];
[img drawInRect:CGRectMake(self.imgView3.image.size.width-10,0,img.size.width, size.height)];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.imgView3.image = finalImage;
[self.imgView3 setFrame:CGRectMake(self.imgView3.frame.origin.x, self.imgView3.frame.origin.y, finalImage.size.width, finalImage.size.height)];
i++;
}
}
现在我想重叠这些图像,即第二张图像应该在第一张图像后面,并将图像置于中心。