Skip to content

Instantly share code, notes, and snippets.

@romyilano
Created November 5, 2014 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romyilano/8227561129938270df8b to your computer and use it in GitHub Desktop.
Save romyilano/8227561129938270df8b to your computer and use it in GitHub Desktop.
squishing 2 images on top of each other
- (IBAction)mergeImages:(id)sender {
UIImage *myFirstImage = [UIImage imageNamed:@"lemonface.png"];
UIImage *myTopImage = [UIImage imageNamed:@"crateKitty-holdingWater.png"];
CGFloat yFloat =10;
CGFloat xFloat = 10;
UIImage *newImage = [self placeImageOnImage:myFirstImage topImage:myTopImage x:xFloat y:yFloat];
[[self theNewImageView] setImage:newImage];
}
-(UIImage *)placeImageOnImage:(UIImage *)image topImage:(UIImage *)topImage
x:(CGFloat)x y:(CGFloat)y
{
// if you want the image to be added next to the image
// make the CGSize bigger
CGSize newSize = CGSizeMake(image.size.width-20, image.size.height/2);
UIGraphicsBeginImageContext(newSize);
[topImage drawInRect:CGRectMake(x, y, topImage.size.width, topImage.size.height)];
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment