iOS中bundle的使用
二、制作Bundle
1.新建bundle項目
? 2.添加需要的圖片 加入你需要編譯在bundle中的資源文件。 當然,默認的配置也是可以的,如果你需要特定的優化或者特定的路徑配置,你可以進行下面第3步的配置。
3.你可以對編譯的bundle進行一些可選的設置(可選) a.作為資源包,僅僅需要編譯就好,無需安裝相關的配置。 ? b.同樣要刪除安裝路徑。 ? c.編譯出適用于iPhone的bundle文件。 ? 三、項目集成bundle
使用bundle就非常的easy了,將編譯好的XXXX.bundle 文件直接加入到需要的項目中。省略了!
四、使用bundle中的資源
1.開始: 將要使用的bundle集成到項目中后,就可以使用了。需要注意的就是,bundle是靜態的,不進行編譯的資源文件。所以,要使用bundle中的資源,就需要找到相應的資源路徑。
2.獲得bundle中的XIB
NSBundle *myBundle = [NSBundle bundleWithPath: [[[NSBundle mainBundle] resourcePath]?
stringByAppendingPathComponent: @"MyBundle.bundle"]];
UIViewController?*vc = [[UIViewController?alloc]?
initWithNibName:@"VC_Name"?bundle:myBundle];
3.獲得bundle中的圖片
NSString?*imgPath= [[myBundle?resourcePath]?
? ? ? ? ? ? ? ? stringByAppendingPathComponent:@"img_collect_success.png"];
UIImageView?*imgView=[[UIImageView?alloc]?initWithFrame:CGRectMake(50,?50,?50,50)];UIImage?*image=[UIImage?imageWithContentsOfFile:imgPath];
[imgView?setImage:?image];
4.當然,可以寫成預編譯語句:
#define MyBundleName @"MyBundle.bundle"
#define MyBundlePath [NSBundle bundleWithPath: [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:MyBundleName]]
總結
以上是生活随笔為你收集整理的iOS中bundle的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机硬件结构控制信息,计算机硬件的基本
- 下一篇: Markdown入门