开发者

How do I join x number of UIImages together?

开发者 https://www.devze.com 2022-12-16 04:37 出处:网络
I\'m looking to stitch some images together, with the images always being added to the bottom of 开发者_如何学Cthe previous image.

I'm looking to stitch some images together, with the images always being added to the bottom of 开发者_如何学Cthe previous image.

e.g. I have images A,B and C. I would like them to appear on top of one another like:

A
B
C

What's the best way to do this?

Thanks!


I did this in the end:

+ (UIImage *)joinImages:(UIImage *)im1 secondImage:(UIImage *)im2 thirdImage:(UIImage *)im3
{
//Joins 3 UIImages together, stitching them vertically
CGSize size = CGSizeMake(320, 480);
UIGraphicsBeginImageContext(size);

CGPoint image1Point = CGPointMake(0, 0);
[im1 drawAtPoint:image1Point];

CGPoint image2Point = CGPointMake(0, im1.size.height);
[im2 drawAtPoint:image2Point];

CGPoint image3Point = CGPointMake(0, im1.size.height +im2.size.height);
[im3 drawAtPoint:image3Point];

UIImage* finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return finalImage;
}


Create a UIView, then add multiple UIImageView instances as subviews. Set the image for each subview, and you're all set. If you have a fixed set of images (or at least a fixed number), you can do all of the layout in InterfaceBuilder. Otherwise, it's just a matter of creating a new UIImageView, then calling addSubView: on the parent view.

http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/addSubview:

If the set of images will be taller than the screen, you'll want to use a UITableView.

0

精彩评论

暂无评论...
验证码 换一张
取 消