A bundle is a directory that contains the resources that the program will use. These resources include like, Sound, compiled code, NIB files ( the user will also refer to bundles as plug-in). Corresponding bundles,
the cocoa provides class nsbundle.
We now use bundles to get a picture of the program and display it on the view.
Create a new single View application and add the following code to the Add Viewdidload method:
[CPP]View Plaincopy
- Get the program's main bundle by using the following method
- NSBundle *mainbundle = [NSBundle mainbundle];
- NSString *imagepath = [Mainbundle pathforresource:@"qq20120616-1" oftype:@ "png"];
- NSLog (@"%@", ImagePath);
- UIImage *image = [[UIImage Alloc]initwithcontentsoffile:imagepath];
- Uiimageview *imageview = [[Uiimageview alloc] initwithimage:image];
- [Self.view Addsubview:imageview];
Right-click on the item, add picture file picture file qq20120616.png.
To run the program:
Print out the image path as follows
/users/rongfzh/library/application Support/iphone simulator/5.1/applications/ 3b8ec78a-5eee-4c2f-b0cb-4c3f02b996d2/iossandbox.app/qq20120616-1.png
We can see that the picture is in the bag of Iossandbox.app,
Picture shows:
The picture is taken out and displayed.
Transferred from: http://blog.csdn.net/totogo2010/article/details/7672271
NSBundle Introduction and use of "go" iOS Learning