Bundle creation is actually a derivative of the previous static library creation.
In the creation of static libraries, our static libraries often carry files, images, and multimedia resources.
You can add the resource files of the plug-in to the project directly. However, we hope to pack the resource files of the plug-in into a package for convenient management.
For example, the UnionPay payment plug-in is used in our project.
In this way, you can directly add the XXXX. Bundle file to the project. In this way, you can directly delete a XXX. Bundle file if you want to delete it in the future.
Of course, some people will also say that it is equally easy for me to directly create a group in the project for management.
At this moment, I can only say one sentence: Is it professional ~.
Three20, UnionPay, and so on. The overall project directory looks simple.
Bundle creation.
1. Create a folder, modify the folder name, and add the suffix XXX. Bundle.
Then you will see that the folder has become a common bundle style folder.
2. Add file resources. In this case, we 'd better create folders for three types of resources
Of course, it doesn't matter if you don't create it, but it is best to create this images folder, because we will put all the image resources here for convenient management.
Then add the image to images.
3. Add the bundle file to the project.
4. Read and use files.
Uilabel * La = [[uilabel alloc] initwithframe: cgrectmake (50,100, 50, 50)]; La. TEXT = @ "Chen Kai"; nsstring * image_url = [[[nsbundle mainbundle] resourcepath] stringbyappendingpathcomponent: @ "Nono. bundle/images/android.png "]; La. backgroundcolor = [uicolor colorwithpatternimage: [uiimage imagewithcontentsoffile: image_url];
In this case, most of the APIs that we used to obtain the uiimage object are directly used:
[Uiimage imagenamed: @ "android.png"]
The method actually finds image resources through the relative path.
However, you cannot use this method to find the image resources in the bundle folder we created.
Each time we specify an image, we need to input a long address, which is troublesome. However, we will find that all images are under XXX. Bundle/images.
You can also use macros or classes to define a method, which is the same as [uiimage imagenamed: @ "android.png. You only need one file name.
For macro performance, refer to
TTIMAGE(@"bundle://Three20.bundle/images/backIcon.png")
An image object is returned.
In the three20 framework, scheme is used, Bundle: // and document; // to load resources in different folders.
Load the image in the Custom bundle folder.
First obtain the absolute path of the application
Mainbundle_path = [nsbundlemainbundle]
Resourcepath];
Then, the path and mainbundle_path following Bundle: // are intercepted and assembled into the final address.
For us, simple implementations can directly use categories
-(UIImage*) imagesNamedFromCustomBundle:(NSString *)name{ NSString *main_images_dir_path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"nono.bundle/images"];// NSAssert(main_images_dir_path, @"main_images_dir_path is null"); NSString *image_path = [main_images_dir_path stringByAppendingPathComponent:name]; return [UIImage imageWithContentsOfFile:image_path];}
Create a category of uiimage and add this extension method.
End