1,新建工程,選擇macOS->Bundle
2,選擇Build Settings,修改以下配置:
"Base SDK" 設置爲 "iOS "
"Build Active Architecture Only" 設置爲 "YES" (Debug,Release均爲YES)(僅編譯當前環境,如果每個環境都編譯一遍會使包變大)
Installation Directiotory 刪除掉後面的路徑 (不安裝相關配置,也不需要安裝路徑)
Code Signing Identity 選擇 "-"
"iOS Deployment Target" 設置爲 iOS 9.0
"Skip Install" 設置爲 "NO" (不需要安裝相關配置)
"Strip Debug Symbols During Copy" 中"Release"模式設置爲 "YES"
"COMBINE_HIDPI_IMAGES" 設置爲 "NO" (不然圖片會是tiff格式)
3,將圖片資源拖入到工程中,或者在Build Phases-Copy Bundle Resources中添加
4,編譯生成bundle。
5,使用方式:
第一種:
UIImage *image = [UIImage imageNamed:@“animate.bundle/001.png"];
第二種:
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"animate.bundle" ofType:nil];
NSBundle *imageBundle = [NSBundle bundleWithPath:bundlePath];
UIImage *image = [UIImage imageNamed:@"001" inBundle:imageBundle compatibleWithTraitCollection:nil];
或者
NSString *path = [imageBundle pathForResource:@"001" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];