Ram Mishra
Ram Mishra

Reputation: 797

How to set UIImageView by code?

Image view I want to set image on uiimage view by coding, i am using below code but image is not showing in my image view.

      UIImage *image = [UIImage imageNamed: @"abc.png"];
      [imageView setImage:image];

Upvotes: 2

Views: 105

Answers (2)

Sachin C
Sachin C

Reputation: 141

UIImage *image = [UIImage imageNamed: @"abc.png"];

use either


  [_imageView setImage:image];

or

 [self.imageView setImage:image];

and please check whether synthesize or not 
if you are synthesized Image view then no need to add _ or self.

Upvotes: 1

Mihir Mehta
Mihir Mehta

Reputation: 13833

Even though you have found the answer, I would like to mention 2 possible reason for this

1> there is no image name abc in your application bundle (could be spelling mistake also)

2> or imageView is nil as in your case

3> or imageView's frame not fit in parent view's bound

4> or imageView is not added as subview in your view

Upvotes: 0

Related Questions