Add Uiimage on Top of Another Uiimage

Add UIImage on top of another UIImage

Try this method:

-(UIImage *)drawImage:(UIImage*)profileImage withBadge:(UIImage *)badge
{
UIGraphicsBeginImageContextWithOptions(profileImage.size, NO, 0.0f);
[profileImage drawInRect:CGRectMake(0, 0, profileImage.size.width, profileImage.size.height)];
[badge drawInRect:CGRectMake(0, profileImage.size.height - badge.size.height, badge.size.width, badge.size.height)];
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}

You can use it by:

UIImage *myBadgedImage = [self drawImage:profileImage withBadge:badgeImage];

Bring UIImageView on top of the other UIImageViews in my main view

[self.view bringSubviewToFront:imageView];

This was what you were looking for...

Saving an image on top of another image in Swift

I would recommend reading through this thread. All your answers are there. Once you read through that article, the following code sample should help you composite the two images together properly.

func saveImage() {
let bottomImage = UIImage(named: "bottom")!
let topImage = UIImage(named: "top")!

let newSize = CGSizeMake(100, 100) // set this to what you need
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)

bottomImage.drawInRect(CGRect(origin: CGPointZero, size: newSize))
topImage.drawInRect(CGRect(origin: CGPointZero, size: newSize))

let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
}

Hopefully this gets you going in the right direction.

How to place the UIImageView at the half of another view in Storyboard

First you need to remove your top space constraint, then you need add a constraint between your UIImageView and your redView, right click and drag to your red view and select align to to Top, later you need to change the first item from .top to .centerY, and add a multiplier value of 1 to be center in your red bottom edge

One Picture worth more than 1000 words

Sample Image

Second requirement

In your second requirement, you need add an helper view I named it guideView this view background will be .clear and userInteraction will be disabled, then guideView will have .top and .bottom constraints to your UIImageView .top and .bottom also will have trailing space to superView with constant 0 and leading space to your UIImageView with constant 0, as shows this image, then your desired green view go inside of guideView and will be aligned center in Vertical and Horizontal to superview and height and width with fixed values and that is all

Sample Image

Hope this helps



Related Topics



Leave a reply



Submit