iOS開發控制項基礎

2021-07-05 23:03:25 字數 2420 閱讀 6819

一、使用plist檔案

使用plist檔案的目的:將資料和**分離。

//載入方法

nsstring *path = [[nsbundle mainbundle] pathforresource:@"imagedata" oftype:@"plist"];

nsarray *imagelist = [nsarray arraywithcontentoffile:path];

二、字典轉模型

1、字典轉模型的優點:

1> 降低**的耦合度

2> 所有字典轉模型部分的**統一集中在一處處理,降低**出錯的機率

3> 在程式中直接使用模型的屬性操作,提高編碼效率

模型應提供乙個可以傳入字典引數的構造方法:

- (instancetype)initwithdict:(nsdictionary *)dict;

+ (instancetype)***withdict:(nsdictionary *)dict;

三、instancetype & id

1、 instancetype在型別表示上,跟id一樣,可以表示任何物件型別

2、 instancetype只能用在返回值型別上,不能像id一樣用在引數型別上

3、 instancetype比id多乙個好處:編譯器會檢測instancetype的真實型別

四、images.xcassets中的素材

1、只支援png格式的

2、只支援[uiimage imagenamed]的方式例項化,但是不能從bundle中載入

3、在編譯時,images.xcassets中的所有檔案會被打包為assets.car檔案

五、uiimageview序列幀動畫

@property (nonatomic, weak) uiimageview *tom

//1.是否正在動畫

[self

.tom isanimating];

//2.設定的陣列

[self

.tom setanimationimages:arraym];

//3.設定動畫時間

[self

.tom setanimationduration:arraym.count * 0.075];

//4.設定動畫迴圈次數,預設為0,無限迴圈

[self

.tom setanimationrepeatcount:1];

//5.開始動畫

[self

.tom startanimating];

[self

.tom performselector:@selector(setanimationimages:) withobject:nil afterdelay:self

.tom

.animationduration];//animationimages 預設是nil

六、載入的兩種方式

1、有快取(占用的記憶體會一直停留在程式中)具體釋放時間由系統決定,適用於小,常用的影象處理

uiimage *image = [uiimage imagenamed:imagename];
2、無快取(所占用的記憶體會在一些特定操作後被清除)

nsstring *path = [[nsbundle mainbundle] pathforresource:imagename oftype:nil];

uiimage *image = [uiimage imagewithcontentsoffile:path];

七、檔案管理

[nsfilemanager defaultmanager]

//判斷檔案是否存在

- (bool) fileexistsatpath:(nsstring *)path;

//將檔案從源路徑複製到目標路徑

- (bool) copyitematpath:(nsstring *)srcpath topath:(nsstring *)despath error:(nserror **)error;

//刪除檔案

- (bool)removeitematpath:(nsstring *)path;

八、plist檔案

1、直接將資料寫在**裡不是一種合理的做法,如果資料經常改,就要經常翻開對應的**進行修改,造成**的擴充套件性低。

2、因此,可以考慮將經常變的資料放在檔案中進行儲存,程式啟動後從檔案中讀取最新的資料。如果需要改變資料,直接修改資料檔案即可,不用修改**

3、解析plist檔案

- (nsarray *)images 

return _images;

}

iOS基礎開發 自定義控制項

自定義控制項,設定子控制項的尺寸和位置 當系統提供的控制項滿足不了我們的需求,我們可以自定義乙個控制項,繼承系統自帶的控制項,寫乙個屬於自己的控制項.自定義控制項的好處是可以把封裝控制項內部的細節,不容易被外界隨意修改.如果乙個view內部的子控制項比較多,一般會考慮自定義乙個view,把它內部子控...

iOS基礎控制項 UIScrollView

uiscrollview的作用是因為手機螢幕有固定大小的侷限性,不能完全展示出想要展示的內容。這個控制項的使用一般有兩種情況 1 對於大的詳細展示 2 輪播圖。uiscrollview在手機的相簿中的使用尤為突出,當我們檢視手機相簿中時,左右滑動切換就是輪播圖的功能,當雙擊螢幕放大在拖動觀察就是展示...

UIButton 按鈕控制項 IOS開發

uibutton是乙個標準的uicontrol控制項,所以如果你對uicontrol不甚了解還是先看一下我的另一篇博文 uicontrol ios控制項程式設計 一 建立 兩種方法 1.常規的 initwithframe uibutton btn1 uibutton alloc initwithfr...