Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refer to an image from the Images.xcassets folder

Here is my code that does not work. I tried first to load the image from file, now I am using a named image:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIImage *imageYouWantToPass = [UIImage imageNamed:@"bl_5_00"];

    self.mainImage.image = imageYouWantToPass;
}

If I put an image in the Images.xcassets folder should the above code work? In other words, if the image is not showing, it is due to a mistake elsewhere in my code?

like image 209
Guido Anselmi Avatar asked Oct 21 '22 12:10

Guido Anselmi


1 Answers

That image should work if you have a group in 'Images.xcassets'. It's case sensitive too so beware. If you just drag and drop the images into the folder, that could be a problem. Click on the .xcassets file in XCode, create a new Image Set and put the image in the boxes.

like image 157
Joey Clover Avatar answered Nov 01 '22 12:11

Joey Clover