hi, How are you guys, Yesterday a friend asked me how to deal with the pictures in the project, Put it inAssets.xcassets Do you, I said yes.
“ You'll pack itBundle Do you?”
“ ah? I can't.”
“ No learning. What are you doing??”
“ Oh, Take time..”
So this article came into being during this lunch break.
What is?Bundle file?
Simple understanding, Is the resource package. We will take many pictures,XIB, Text files organized together, Pack into oneBundle file. Convenient to reference resources within the package in other projects.
Bundle Characteristics of documents?
Bundle It's static. In other words, The resource files we include in the package are not compiled as a resource package. Which means,bundle Package cannot contain executable files. It's just a resource, Resolved to specific2 Binary data.
1. Create a new projectmacOS OfBundle project
3. Delete folders andinfo.plist file
4. deleteBuild Settings LiPackaging Ofinfo.plist File address for
5. Set upBase SDK byiOS
6. Add resource files to be packaged into folder
7. I added a picture
8. Compile, Then find the button below to open the folder
9. findBundle file, Right click to display package content, See if you want to add resource files to it
10. After checking, takeBundle copy toiOS Item
11. Start using
This is a way, There are other ways.
NSString * bundlePath = [[ NSBundle mainBundle] pathForResource: @ "MyBundle"
ofType :@ "bundle"];
NSBundle *resourceBundle = [NSBundle bundleWithPath:bundlePath];
UIViewController *vc = [[UIViewController alloc] initWithNibName:@"vc_name"
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 50,
NSString *imgPath= [bundlePath stringByAppendingPathComponent:
UIImage *image_1=[UIImage imageWithContentsOfFile:imgPath];
#define MYBUNDLE_NAME @ "MyBundle.bundle"
#define MYBUNDLE_PATH [[[NSBundle mainBundle] resourcePath]
#define MYBUNDLE [NSBundle bundleWithPath: MYBUNDLE_PATH]