Created
November 5, 2014 07:12
-
-
Save romyilano/8227561129938270df8b to your computer and use it in GitHub Desktop.
squishing 2 images on top of each other
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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