Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically change the UIImageView displaying image1 to image2

The UIImageView is placed in interface builder. I already created an IBOutlet. How do i programmatically change the UIImageView to view another image.

Can someone please help me?

like image 760
Pavan Avatar asked Jan 31 '10 16:01

Pavan


People also ask

How do I change my photo on UIImageView?

Once you have an Image you can then set UIImageView: [imageView setImage:image]; The line above assumes imageView is your IBOutlet. That's it!

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .

How do you declare UIImage in Objective C?

For example: UIImage *img = [[UIImage alloc] init]; [img setImage:[UIImage imageNamed:@"anyImageName"]]; My UIImage object is declared in . h file and allocated in init method, I need to set image in viewDidLoad method.


1 Answers

If myImageView is your outlet, then in code, you can use:

myImageView.image = [UIImage imageNamed: @"myNewImage.png"];
like image 198
Ben Gottlieb Avatar answered Oct 23 '22 10:10

Ben Gottlieb