开发者

Accessing resources in the package of an application created with xcode/cocoa

开发者 https://www.devze.com 2022-12-25 03:48 出处:网络
I am trying to make a simple that needs to create an NSImage and I want to put the .png file in the resources of my package contents.I added the .png file to my resources directory in Xcode and when I

I am trying to make a simple that needs to create an NSImage and I want to put the .png file in the resources of my package contents. I added the .png file to my resources directory in Xcode and when I create the applicaiton the .png fi开发者_开发知识库le shows up in my resources inside package contents but I am havhing trouble figuring out how to reference file here is what I tried:

[image initWithContentsOfFile:@"resources/draw-button.png"];

I figured that my package contents would be my current directory so I thought this would work, but it does. How do I reference my resources directory?


You want to use NSBundle:

NSString *path = [[NSBundle mainBundle] pathForResource:@"draw-button" ofType:@"png"];
NSImage *img = [[NSImage alloc] initWithContentsOfFile:path];


Try [UIImage imageNamed:@"draw-button.png"].

"Resources" is just an organizational category in XCode, not a true folder in the application bundle.

0

精彩评论

暂无评论...
验证码 换一张
取 消