HillInHarwich
HillInHarwich

Reputation: 449

How can I embed small images into my app?

I have 4 small "LED" icons which I use in my app to indicate the status of the objects in a UITableView and in a subsequent detail view. I don't really want to have to store them online - is there some way to save them as a part of the app? If so, how do I then reference them?

Upvotes: 1

Views: 245

Answers (2)

Justin Ohms
Justin Ohms

Reputation: 3523

UIImage *image = [UIImage imageNamed:@"yourImage"];

Upvotes: 0

Dr.Kameleon
Dr.Kameleon

Reputation: 22820

Just drag-and-drop them in your Xcode project.

Then, to "reference" them, you could just use :

[[NSBundle mainBundle] pathForResource:@"yourImage" ofType:@"png"];

To get the actual NSImage (from your app bundle) :

NSString* imagePath = [[NSBundle mainBundle] pathForResource:@"yourImage" ofType:@"png"];
NSImage* image = [[NSImage alloc] initWithContentsOfFile: imagePath];

Upvotes: 2

Related Questions