iOS開發UI篇—簡單的瀏覽器查看程式

來源:互聯網
上載者:User

標籤:

一、程式實現要求

1.要求

2. 介面分析

(1) 需要讀取或修改屬性的控制項需要設定屬性

序號標籤

圖片

圖片描述

左邊按鈕

右邊按鈕

(2) 需要監聽響應事件的對象,需要添加監聽方法

左邊按鈕

右邊按鈕

 

3.一些新的屬性與方法

3.1

UILabel *headlab=[[UILabel alloc]initWithFrame:CGRectMake(20, 10, 300, 30)]; 38      39   // [headlab setText:@"1/5"]; 40     [headlab setTextAlignment:NSTextAlignmentCenter];  //文字置中 41     [headlab setTextColor:[UIColor blackColor]];

3.2
//控制按鈕的點擊,如果為5則右鍵失效,如果為1,則左鍵失效126     self.leftbtn.enabled=(self.i!=0);127     self.rightbtn.enabled=(self.i!=4);


3.3
 //array的get方法161 -(NSArray *)array162 {163     NSLog(@"需要擷取數組");164     //只執行個體化一次165     if (_array==nil) {166         NSLog(@"執行個體化數組");167         NSDictionary *[email protected]{@"name": @"biaoqingdi",@"desc":@"什麼表情都弱爆了!"};168         NSDictionary *[email protected]{@"name": @"bingli",@"desc":@"病例"};169         NSDictionary *[email protected]{@"name": @"wangba",@"desc":@"烏龜"};170         NSDictionary *[email protected]{@"name": @"chiniupa",@"desc":@"吃牛扒"};171         NSDictionary *[email protected]{@"name": @"danteng",@"desc":@"蛋疼"};172         [email protected][dict1,dict2,dict3,dict4,dict5];173     }174 //    NSDictionary *[email protected]{@"name": @"biaoqingdi",@"desc":@"什麼表情都弱爆了!"};175 //    NSDictionary *[email protected]{@"name": @"bingli",@"desc":@"病例"};176 //    NSDictionary *[email protected]{@"name": @"wangba",@"desc":@"烏龜"};177 //    NSDictionary *[email protected]{@"name": @"chiniupa",@"desc":@"吃牛扒"};178 //    NSDictionary *[email protected]{@"name": @"danteng",@"desc":@"蛋疼"};179     180    // [email protected][dict1,dict2,dict3,dict4,dict5];181     return _array;182 }

3.4

使用plist檔案

(1)使用Plist檔案的目的:將資料與代碼分離

(2)載入方法:

NSString *path = [[NSBundle mainBundle] pathForResource:@"ImageData" ofType:@"plist"];

_imageList = [NSArray arrayWithContentsOfFile:path];

提示:通常在方法中出現File字眼,通常需要傳遞檔案的全路徑作為參數

 -(NSArray *)array111 {112     NSLog(@"需要擷取數組");113     //只執行個體化一次114     if (_array==nil) {115      116         NSString *path=[[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];117         //數組的資料從檔案擷取118        // _array=[NSArray arrayWithContentsOfFile:path];119         _array=[[NSArray alloc]initWithContentsOfFile:path];120         //列印查看包的位置121         NSLog(@"%@",path);122         123        NSLog(@"執行個體化數組");124     }125 126     return _array;127 }


4.1

補充

開發思路:

1.完成準系統

2.考慮效能

(1)(初始化操作,可以直接調用change進行)

(2)因為要控制序號和圖片兩個變數,所以考慮使用字典代替掉switch

(3)每次點擊,字典都需要建立一次,效率地下,可以考慮建立的這部分拿到初始化方法中去,這樣就只需要建立一次就ok了。

(4)考慮缺點(對代碼的順序要求極其嚴格)

(5)懶載入(需要的時候才載入,那麼什麼時候是需要的時候,及調用get方法的時候)

(6)每次都來一下?效率低下—》只有第一次調用get方法時為空白,此時執行個體化並建立數組,其他時候直接返回成員變數(僅僅執行一次)

注意點:

1.方法的呼叫堆疊(順序)。

2.使用plist:讓資料的操作更加靈活,把資料弄到外面去,解除耦合性,讓耦合性不要太強。實際上是一個xml,是蘋果定義的一種特殊格式的xml。

3.bundle-包(唯讀)

iOS開發UI篇—簡單的瀏覽器查看程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.