Creation and use of bundle files

Source: Internet
Author: User

There is often a need to encapsulate your own modules or open classes into static libraries to provide convenient calls to others.

But when you need to use a lot of xib, pictures, audio or other resource files in your module, you can't add them to the static library. At this point, some resource files need to be encapsulated. Bundle file. Well, the packaged stuff should contain three types of files:

1: Open header file (contains full call notes)

2: Static library file suffix named. A

3:bundle file for storing various resource files.

So the rest is simple: here is a specific package of bundle files (in fact, very simple)

First step: Create a bundle project

Select the bundle file type and create the project.

Step Two: Modify buildsetting Related Settings

1:base SDK modified to iOS6 or other existing iOS SDK versions

2:architectures modified to ARMv7 armv7s

Step Three: Add the resource file you want to add

Fourth Step: Build (This does not require a certificate and can be compiled successfully)



This generates your own bundle.

When called, the help needs to be referenced to the project in the line, as follows:

Introduction method in the program:

1 get the resources in the bundle2 3NSString * Bundlepath = [[NSBundle mainbundle] Pathforresource: @"Mybundle"OfType: @"Bundle"];4NSBundle *resourcebundle =[NSBundle Bundlewithpath:bundlepath];5Uiviewcontroller *VC = [[Uiviewcontroller alloc] Initwithnibname:@"Vc_name"Bundle:resourcebundle];6 7 picture Gets the resources in the bundle8 9Uiimageview *imgview=[[uiimageview Alloc] Initwithframe:cgrectmake ( -, -, -, -)];TenUIImage *image = [UIImage imagenamed:@"mybundle.bundle/img_collect_success"]; One [Imgview setimage:image]; A  - or -  theUiimageview *imgview=[[uiimageview Alloc] Initwithframe:cgrectmake ( -, -, -, -)]; -NSString *imgpath= [Bundlepath stringbyappendingpathcomponent:@"Img_collect_success.png"]; -UIImage *image_1=[UIImage Imagewithcontentsoffile:imgpath]; - [Imgview setimage:image_1]; +  - of course, it can be written as a precompiled statement: + #defineMybundle_name @ "Mybundle.bundle" A #defineMybundle_path [[[NSBundle Mainbundle] ResourcePath] stringbyappendingpathcomponent:mybundle_name] at #defineMybundle [NSBundle Bundlewithpath:mybundle_path]

If you want to be called in a non-mainbundle place. Then you need to load this bundle extra

Creation and use of bundle files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.