下面向通过颜色创建了一张空白图片,然后将目标图片居中在上一个图片中,这里可以通过同样的方法绘制多张图片到一张图片上去
- (UIImage *) drawRectForImage:(UIImage *) image {UIImage* rectImage = [UIImage imageWithColor:[UIColor whiteColor] size:CGSizeMake(self.frame.size.width, image.size.height + 20)];CGSize finalSize = [rectImage size];CGSize imageSize = [image size];UIGraphicsBeginImageContext(finalSize);[rectImage drawInRect:CGRectMake(0,0,finalSize.width,finalSize.height)];[image drawInRect:CGRectMake((finalSize.width - imageSize.width)/2,10,imageSize.width,imageSize.height)];UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();return newImage;}