Problem when displaying image with Uiimageview

Asked

Viewed 102 times

0

When displaying image included in project format .png using UIImageView to only display the simulator screen is blank.

Code used:

UIImage* imagemLocal = [UIImage imageNamed:@"button.png"];
_imagemViewLocal = [UIImageView alloc]initWithImage:imagemLocal];

Or:

UIImage* imagemLocal = [UIImage imageNamed:@"button.png"];
_imagemViewLocal = [[UIImageView alloc]init];

[_imagemViewLocal setImage: imagemLocal];

The result is the same ImageViewLocal goes blank.

NOTE: I added one UIImageView for Sotryboard and connected it with _imageViewLocal.


I ended up performing the following test: - I removed the UIImageView raised in the Storyboard and did everything directly in the code. And displayed the image with the following code:

UIImageView* imageViewLocal = [[UIImageView alloc]init];
imagemLocal = [UIImage imageNamed:@"button.png"];
imageViewLocal = [[UIImageView alloc]initWithImage:imagemLocal];

[self.view addSubview: imageViewLocal];

inserir a descrição da imagem aqui

How to solve the reported problem?

  • Have you checked whether imageNamed is returning nil?

  • Yes already checked, is not returning nil, is loading the image normally. Very strange this.

  • Updating question!

  • I did a test creating everything in the code, and it worked, but I still prefer to use the storyboard because to speed up the process.

  • Do a test: add again to ImageView in Storyboard, plug it in with the variable and change the background color just to see if it’s visible in the current view.

  • I’m gonna take the test!

  • Yes, I changed the background color to red and it worked with the Uiimageview link created by Storyboard

  • Now it worked!!! I’ll post the answer!!! very crazy Xcode today huh!! My, I think it’s the heat! rs

Show 3 more comments

2 answers

1

Try to use that:

UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
    [imgView setImage:[UIImage imageNamed:"image.png"]];
    [self.view addSubview: imgView];

0


Xcode behaved very strangely. But now it worked.

I did a direct attribution to the image property of the object. I had tried the same operation and it didn’t work. But now it worked.

Note: Uiimageview added from Storyboard.

Code:

imagemLocal = [UIImage imageNamed:@"button.png"];
 _imageViewTesteFundo.image = imagemLocal;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.