ios-generating bundles-introducing bundle-using bundles

Source: Internet
Author: User

When we use a third-party framework, we often see xxx.bundle files. We find the file, show the package content, and see a lot of resource files: Pictures, configuration text, xib files ... What is a bundle file? A simple understanding is a resource file package. We organize many pictures, XIB and text files together and package them into a bundle file. facilitates referencing resources within packages in other projects. What are the characteristics of bundle files? The bundle is static, that is, the resource file that we include into the package is not compiled as a resource bundle without participating in the project. It also means that the bundle package cannot contain executable files. It is only as a resource and is parsed into a specific 2 binary data. Making Bundles 1. New Bundle Project
2. Add the desired pictureAdd the resource files that you need to compile in the bundle. Of course, the default configuration is also possible, if you need a specific optimization or specific path configuration, you can proceed to the 3rd step below configuration. 3. You can make some optional settings for the compiled bundles (optional) A. As a resource bundle, you just need to compile it, no need to install the relevant configuration. B. Also remove the installation path. c. pch files and strings files for this resource bundle can be deleted. 4. In the best state, compile the bundle file for the iphone. Project Integration BundleUsing bundles is very easy, and the compiled Xxxx.bundle files are added directly to the desired project. It's omitted! using the resources in the bundleOnce the bundles that will be used are integrated into the project, you can use them. It is important to note that the bundle is static and does not compile the resource file. Therefore, to use the resources in the bundle, you need to find the appropriate resource path. There is no more nonsense here, put the code! VC Gets the resources in the bundle

NSString * Bundlepath = [[nsbundle Mainbundle] pathforresource: @ "Mybundle" ofType: @ "bundle"];

NSBundle *resourcebundle =[nsbundle Bundlewithpath:bundlepath];

Uiviewcontroller *VC =[[uiviewcontroller alloc] initwithnibname:@ "Vc_name" Bundle: ResourceBundle];

picture Gets the resources in the bundle

Uiimageview *imgview=[[uiimageview alloc] initwithframe: CGRectMake( )];

UIImage *image = [uiimageimagenamed:@ "mybundle.bundle/img_collect_success"];

[Imgview setimage:image];

or

Uiimageview *imgview=[[uiimageview alloc] initwithframe: CGRectMake( )];

NSString *imgpath= [Bundlepathstringbyappendingpathcomponent:@ "Img_collect_success.png"];

UIImage *image_1=[UIImage imagewithcontentsoffile: Imgpath];

[Imgview setimage:image_1];

Of course, it can be written as a precompiled statement:

#define MYBUNDLE_NAME @ "Mybundle.bundle"

#define MYBUNDLE_PATH [[[NSBundle Mainbundle] resourcepath]stringbyappendingpathcomponent:mybundle_name]

#define Mybundle [NSBundle Bundlewithpath:mybundle_path]

plane ticket:http://blog.sina.com.cn/s/blog_7b9d64af0101jmj2.html hope to help you!

ios-generating bundles-introducing bundle-using bundles

Related Article

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.