1。首先添加bundle到工程中,
在xcode中点击Project出现下面视图

点击Add Target

选择bundle
2。将资源添加到该Bundle中
在Build Phase中添加需要的资源

3。使用该Bundle
NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"BundleName" ofType:@"bundle"]];
NSString *imageName = [bundle pathForResource:@"close_button" ofType:@"png"];
NSLog(@"bundle:%@--image:%@",bundle,imageName);
UIImage *closeButton = [[UIImage alloc] initWithContentsOfFile:imageName];
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:closeButton];
[self.view addSubview:tempImageView];
tempImageView.frame = CGRectMake(100, 100, 43, 43);更复杂的使用参考Apple官方文档
本文介绍如何在iOS项目中使用Bundle来组织资源文件。包括添加Bundle到项目、将资源添加到Bundle以及如何在代码中引用这些资源的具体步骤。


被折叠的 条评论
为什么被折叠?



