从两个较小的UIImages创建UIImage

Sun*_*day 2 image-manipulation core-graphics uiimage ios

我有两个实例UIImage.如何创建第三个UIImage只是拼接在一起的两个原始图像?我希望顶部的第一个图像和底部的第二个图像使得顶部图像的底部边缘与底部图像的顶部边缘齐平.

wat*_*n12 6

像这样的东西应该工作(虽然我没有测试过)

-(UIImage *)imageWithTopImage:(UIImage *)topImage bottomImage:(UIImage *)bottomImage
{
    UIGraphicsBeginImageContext(CGSizeMake(topImage.size.width, topImage.size.height + bottomImage.size.height);
    [topImage drawInRect:CGRectMake(0, 0, topImage.size.width, topImage.size.height)];
    [bottomImage drawInRect:CGRectMake(0, topImage.size.width, bottomImage.size.width, bottomImage.size.height)];
    UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return combinedImage;
}
Run Code Online (Sandbox Code Playgroud)