在framework中打包xib 【轉】

來源:互聯網
上載者:User

標籤:

廢話不多說,直接

1、Copy Bundle Resources 中加入相關xib

2、這裡是重點,調用的時候不能直接寫

 

 

[objc] view plaincopy 
  1. [[NSBundle mainBundle] loadNibNamed:@"yourXibName" owner:nil options:nil]  


而要加入framework中的路徑,否則在調用的時候會報找不到xib檔案(路徑不同)的錯,繼而crash

 

 

[objc] view plaincopy 
  1. [[NSBundle mainBundle] loadNibNamed:@"yourframework.framework/yourXibName" owner:nil options:nil]  

 

 

3、編譯完成後可以看到在framework目錄下產生了對應的nib檔案(xib編譯之後產生nib,詳情自己搜吧)

 

4、然後在項目配置的時候,需要把framework加入到Copy Bundle Resources 中,這一步也是重點

 

不過這樣會增加整個包的大小

因此個人認為還是使用.a+bundle的形式更為妥當

另外如果在xib中直接載入了圖片資源,則需要使用代碼進行重新設定,因為無論是framework的形式還是.a+bundle的形式,資來源目錄都發生了改變,不再是從.app的根目錄下去取資源,而是在.app目錄下的bundle或者framework目錄中取,因此載入資源的方式也需要變更

 

[objc] view plaincopy 
  1. + (NSString *)pathForResource:(NSString *)name ofType:(NSString *)type {  
  2.     NSBundle *bkBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:YOUR_BUNDLE_NAME ofType:@"bundle"]];  
  3.     NSString* path = [bkBundle pathForResource:name ofType:type];  
  4.     return path;  
  5. }  


還有一個蛋疼的地方需要注意,在xcode6下,combine_hidpi_images的預設設定項為yes,需要手動改為no,否則bundle中的png圖片經過編譯打包會變成tiff的檔案,進而導致對應圖片找不到

 

 

 

 

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

在framework中打包xib 【轉】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.