Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8976247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:05:11+00:00 2026-06-15T19:05:11+00:00

I have a UIImageView object that I instantiate and turn into a property inside

  • 0

I have a UIImageView object that I instantiate and turn into a property inside my iOS app. I initialize the attributes for this UIImageView object inside my viewDidLoad method, however, I need to change the image that is contained inside the UIImageView object later on in another method. When I do this, I for some reason am simply superimposing the new image over top of the old one. What I would like to do is simply resize the frame, and replace the old image with the new one.

Here is the relevant code:

Inside my viewDidLoad method:

imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 250, 300, 200)];
imageView.image = [UIImage imageNamed:@"firstImage.png"];
[self.view addSubview:imageView];

and inside my method where I wish to make the changes:

imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 250, 200, 300)];
imageView.image = [UIImage imageNamed:@"secondImage.png"];
[self.view addSubview:imageView];

Please bear in mind that I don’t want to just change the image, but also the frame size to accommodate the new image. Can anyone see what I am doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:05:12+00:00Added an answer on June 15, 2026 at 7:05 pm

    You are creating another instance of imageview. You need to access the same object and change frame and image there.

    Try this,

    Create imageView as property in the class as,

    In .h file,

    @property(nonatomic, retain) UIImageView *imageView;
    

    Then in viewDidLoad,

    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 250, 300, 200)];
    self.imageView.image = [UIImage imageNamed:@"firstImage.png"];
    [self.view addSubview:imageView];
    

    The in second method, just change the frame and image as shown below,

    self.imageView.frame = CGRectMake(10, 250, 200, 300);
    self.imageView.image = [UIImage imageNamed:@"secondImage.png"];
    

    As per you code, you were creating separate instances for imageViews and adding as subviews which will cause it to superimpose on another one. Instead you need to create a single instance as shown above and modify its frame and image properties whenever required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIImageView object that I rotate with frame property and CFAffineTransformMakeRotate and
I have a UIImageView object that when clicked it will play a animation, I
Example: I have an class that inherits from UIImageView. An object creates an instance
i have a UIImageView object that i'm trying to get x coordinate of. I
Hello i have a uiscrollview and i have one object of uiimageview inside the
Say I have a UIImageView that contains an image of an object that is
I have a UIImageView object X that is contained in an TableView object A.
I have an object that the user has to drag around the screen. This
I have an UIImageView object in one of my viewController view that is preloaded
I have an object that return a cached image view (UIImageView), which do the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.