Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlay an UIImage above an UIImageView, possible? example code?

Is it possible to set an image over an other image, respectively to overlay an image above an UIImage.

I give some code:

  • Headerfile:

    @property (nonatomic,assign)UIImageView* imageView;
    
  • Implementationfile

    UIImage *overlayImage = [UIImage imageNamed:@"lamp.png"];
    

The "imageView.image" has got an image and above that I will have this lamp, but later on it has to be possible to move it.

I searched some methods, but all methods gave me warnings.

Could you help me how to manage it? And is Core Animation an alternative to handle that?

like image 991
Studie Avatar asked Apr 20 '26 20:04

Studie


2 Answers

Just add it as a subview. UIImageView is a UIView like any other.

UIImage *overlayImage = [UIImage imageNamed:@"lamp.png"];
UIImageView *overlayImageView = [[UIImageView alloc] initWithImage:overlayImage];
[self.imageView addSubview:overlayImageView];
like image 149
kubi Avatar answered Apr 22 '26 09:04

kubi


You should use another UIImageView. A UIImage doesn't refer to an actual view in the interface, it's used as a reference to an image to be reused in code.

UIImageView* lampImageView= [[UIImageView alloc] initWithImage:overlayImage];

This way you can move it around anywhere over the first image view.

like image 32
Luke Avatar answered Apr 22 '26 10:04

Luke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!