首页 > 编程知识 正文

humble bundle慈善包,mirror bundle 捆绑包

时间:2023-05-06 06:07:01 阅读:226890 作者:519

参考文章

制作APP中,我们可以用bundle来管理资源文件.

一、什么是Bundle文件

简单理解,就是资源文件包。我们将许多图片、XIB、文本文件组织在一起,打包成一个Bundle文件。方便在其他项目中引用包内的资源。

二、Bundle文件的特点

Bundle是静态的,也就是说,我们包含到包中的资源文件作为一个资源包是不参加项目编译的。也就意味着,bundle包中不能包含可执行的文件。它仅仅是作为资源,被解析成为特定的2进制数据。

三、制作Bundle

1.新建bundle项目

新建bundle.png

bundle_name.png

2.添加需要的资源文件

加入你需要编译在bundle中的资源文件。

添加资源文件.png

3.编译bundle

编译bundle.png

4.项目集成bundle

将制作好的bundle拖拽到项目中.

5.使用bundle中的资源

宏.png

#define MYBUNDLE_NAME_2 @"BundleTest2.bundle"

#define MYBUNDLE_PATH_2 [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: MYBUNDLE_NAME_2]

#define MYBUNDLE_2 [NSBundle bundleWithPath: MYBUNDLE_PATH_2]

#define MYBUNDLE_NAME_3 @"Bundle3.bundle"

#define MYBUNDLE_PATH_3 [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: MYBUNDLE_NAME_3]

#define MYBUNDLE_3 [NSBundle bundleWithPath: MYBUNDLE_PATH_3]

代码.png

// 从bundle中加载xib

UIView *view = [[MYBUNDLE_2 loadNibNamed:@"MyView" owner:self options:nil] objectAtIndex:0];

view.frame = self.view.frame;

[self.view addSubview:view];

// 从bundle中加载图片

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

imageView.image = [UIImage imageWithContentsOfFile:[MYBUNDLE_PATH_2 stringByAppendingPathComponent:@"Contents/Resources/share_pengyouquan"]];

[view addSubview:imageView];

// 从另一个bundle中加载storyboard

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Bundle3Storyboard" bundle:MYBUNDLE_3];

NSLog(@"storyboard = %@",storyboard);

// 从另一个bundle中加载图片

UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(250, 100, 100, 100)];

imageView2.image = [UIImage imageWithContentsOfFile:[MYBUNDLE_PATH_3 stringByAppendingPathComponent:@"Contents/Resources/guanyudingyue"]];

[view addSubview:imageView2];

效果.png

APP中的bundle.png

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。