接上篇文章,继续创建.bundle文件
1、首先在MyLbrary中添加bundle,名称为:LibraryResources

2、因为bundle默认是OS系统的,所有需要修改他的信息。如图,修改成iOS系统

3、设置Build Setting中的COMBINE_HIDPI_IMAGES 为NO,否则bundle中的图片就是tiff格式了

4、创建一个测试类:MyViewController ,创建的时候记得带上xib,创建完毕后,把MyViewController.xib拖到LibraryResources项目下,结果如下图

5、再向里面添加随便一个图片,在Xib上创建一个button,设置他的image为这个图片,如下如

6、然后修改MyLibrary类,如下
#import <Foundation/Foundation.h>
#import "MyViewController.h"
@interface MyLibrary : NSObject
+ (void)logMyLibrary;
+ (MyViewController *)creatMyViewController;
@end
#import "MyLibrary.h"
@implementation MyLibrary
+ (void)logMyLibrary {
NSLog(@"输出我的Library啦");
}
+ (MyViewController *)creatMyViewController {
NSString * rescourcePath = [[NSBundle mainBundle] pathForResource:@"LibraryResources" ofType:@"bundle"];
NSBundle * bundle =[NSBundle bundleWithPath:rescourcePath];
MyViewController * myVC =[[MyViewController alloc]initWithNibName:@"MyViewController" bundle:bundle];
return myVC;
}
@end
并把MyViewController.h文件也暴露出来,不然会报错的

7、接下来分别运行这两个target,然后按照上篇文章一样生成MyLibrary文件


8、把MyLibrary 文件拖入测试项目就可以测试啦。

至此.a静态库和.bundle文件都创建完毕啦
网友评论