Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load an image from "Images.xcassets" into an NSImage*?

Not sure how else to specify the path to the image.

I've added a png into a new image named "StatusBarIcon", which lives inside "Images.xcassets" resource folder.

I see they put a json file and what not.

Tried to do what the examples out there say, but no matter what I try, I always get nil as the output of [NSImage imageNamed:@"name of paths attempted here"]

Won't load using the full path either, I suppose the method is looking for the name of the image, but I've no idea how to specify the name correctly it seems, or perhaps I need another method?

Here are screenshots of my code, and my project. different attempts and log output showing it's always nilwhat my image is like

like image 956
Gubatron Avatar asked Sep 20 '14 00:09

Gubatron


1 Answers

Make sure you have the project set to use xcassets instead of just individual resource files. Once you create an image in the xcasset, you should just specify the name of the image, not the path. For example, [NSImage imageNamed:@"StatusBarIcon"]

like image 157
contactritsard Avatar answered Nov 10 '22 14:11

contactritsard