IOS初學者 bundle知識點總結

2021-09-11 09:15:26 字數 1402 閱讀 5830

在ios開發中,使用的方式有兩種一種方式可以將散落在工程中,一種方式可以用bundle統一管理。

如果用這種形式,可以使用一下**進行獲取

uiimage *img1 = [uiimage imagenamed:@"umeng_share_solid_icon"];

我們可以把整個工程看做是乙個bundle,也就是mainbundle,這樣可以使用如下方法讀取:

nsbundle *mainbundle = [nsbundle mainbundle];

// 用物件mainbundle獲取路徑

nsstring *imagepath = [mainbundle pathforresource:imgname oftype:@"png"];

return [[uiimage alloc] initwithcontentsoffile:imagepath];複製**

在工程目錄下新建乙個資料夾,改名為***.bundle,一定要以.bundle為字尾。

以後開啟此資料夾,要滑鼠右鍵-顯示包內容,直接雙擊不行。

nsbundle *bundle = [nsbundle bundlewithpath:bundlepath];

nsstring *img_path = [bundle pathforresource:imgname oftype:@"png"];

[uiimage imagewithcontentsoffile:img_path];複製**

nsbundle *bundle = [nsbundle bundlewithpath:bundlepath];

nsstring *txtpath = [bundle pathforresource:name oftype:@"txt"];

return [[nsstring alloc] initwithcontentsoffile:txtpath encoding:nsutf8stringencoding error:nil];複製**

那麼自定義bundle中的能不能以路徑的形式獲取呢?當然可以

uiimage *img3 = [uiimage imagenamed:@"image.bundle/umeng_share_solid_icon"];
上面提到過可以把整個工程的group看做是mainbundle

那麼也就可以這樣讀取了

nsstring *file2 = [[nsbundle mainbundle] pathforresource:@"image.bundle/***" oftype:@"png"];

uiimage *img2 = [uiimage imagewithcontentsoffile:file2];複製**

對初學者很重要的c語言知識點

順序結構 1,輸入變數的值 scanf 格式控制符 變數 2.定義字元 char 3.字元的輸入輸出 ch getchar putchar ch 選擇結構 不含else選擇結構 if 表示式 含else選擇結構 if 表示式 else 語句 條件表示式構成的選擇結構 表示式1?表示式2 表示式3 選...

iOS開發初學者入門需要學習哪些知識?

都說網際網路的快速發展改變著人們的就業生活方式,於是像程式設計師這樣的技術性崗位就成為大家爭相追逐的崗位,作為一項技術性ios開發崗位,高門檻,高收入總是伴隨著這一行業,所以現在越來越多的新人選擇從事ios開發工作,其中不乏一些轉行的程式設計師。那麼什麼是ios,ios是蘋果公司最早於07年公布的移...

給ios初學者的建議

不管你是培訓的還是在上學的或者是自學的!你選擇了這條路就要認真的對待你所學的,別出來找工作什麼都不會!首先,第一點 把你的obj c語言基礎打好,在學習obj c之前最好學一下c c 除此之外最好各課都要設計了解些,xml,json,mysql,html,js!我碰到乙個連json和xml是什麼都不...