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
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
Hope this helps
Related Topics
iOS Facebook Login "Given Url Is Not Allowed by the Application Configuration"
Why Is an Nsdate in a Core Data Managed Object Converted to Nstimeinterval
iOS 11 Search Bar Jumping to Top of Screen
Xcode 7 Beta 6, Dyld _Nsarray0_ Crash
How to Upload Multiple Image on Firebase Using Swift
Xamarin "The Executable Was Signed with Invalid Entitlements"
Does Swift Not Work with Function Pointers
How to Send a Uilongpressgesture Programmatically
Crashlytics Does Not Show Crashes
Avplayer with Playback Controls of Avplayerviewcontroller
iOS Notification Trigger: Fortnightly And/Or Quarterly
App Crashes in Background While Changing Permission - Swift
Autolayout: Origin and Size Should Change According to Width and Height Factor
Cashapelayer Animating Path Glitches/Flickers (From Ellipse to Rect and Back)
Searching Through Child Values Firebase/Swift
Core Data Sum of All Instances Attribute
iOS Uimenucontroller Uimenuitem, How to Determine Item Selected with Generic Selector Method