Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make UIImageView change its image programmatically?

I have this code:

- (void)viewDidLoad {
[super viewDidLoad];
landscape.image = [UIImage imageNamed:@"tenerife1.png"];
}

First, I created an UIImageView with IBOutlet. Landscape is pointing to that UIImageView. In InterfaceBuilder I told to show an specific image in that UIImageView. It never changes. I always see the image I specified in InterfaceBuilder. But I want to set it programmatically. How can I do this?

like image 993
Thanks Avatar asked Apr 01 '09 16:04

Thanks


People also ask

How do I add an image to UIImageView?

The first step is to drag the UIImageView onto your view. Then open the UIImageView properties pane and select the image asset (assuming you have some images in your project). You can also configure how the underlying image is scaled to fit inside the UIImageView.

What is the difference between UIImage and UIImageView?

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


1 Answers

Try calling setNeedsDisplay on the view after you change the image:

   [landscape setNeedsDisplay];
like image 193
Eric Petroelje Avatar answered Oct 05 '22 10:10

Eric Petroelje