[iOS基礎控制項 - 3.3] 圖片瀏覽器

來源:互聯網
上載者:User

標籤:des   style   blog   io   ar   color   os   使用   sp   

需求:1.顯示當前圖片序號/總圖片數2.顯示圖片3.上一張圖片、下一張圖片轉換4.顯示圖片描述  A.資料的載入方式1.逐個載入、處理2.使用數組、字典分離資料和邏輯3.消極式載入     將初始化放在getter初始化,當需要的資料不存在才初始化4.使用plist     儲存資料在外部檔案,剝離資料和邏輯代碼     不要使用帶”info”的名字,會跟系統檔案混淆 a.使用NSBundle獲得手機全路徑    
 1 if (_imageData == nil) { 2         // 初始化資料 3         // File: 全路徑 4         // NSBoundle: 一個NSBoundle代表一個檔案夾 5         // 利用mainBundle就可以訪問手機裡面的任何資源 6         NSBundle *bundle = [NSBundle mainBundle]; 7         8         // 獲得imageData.plist的全路徑 9         NSString *path = [bundle pathForResource:@"imageDate" ofType:@"plist"];10         _imageData = [NSArray arrayWithContentsOfFile:path];11     }
 b. plist檔案的解析過程逐層解析、封裝  c.轉換圖片
 1 #pragma mark 轉換圖片 2 - (void) changeData { 3     // 1.設定當前圖片的序號標題 4     self.noLabel.text = [NSString stringWithFormat:@"%d/%d", self.index + 1, self.imageData.count]; 5      6     // 2.取出當前的圖片資料 7     NSDictionary *currentImageData = self.imageData[self.index]; 8      9     // 3.設定圖片10     self.iconView.image = [UIImage imageNamed:currentImageData[IconKey]];11     12     // 4.設定圖片描述13     self.descLabel.text = currentImageData[DescKey];14     15     // 5.改變按鈕狀態16     self.previousButton.enabled = (self.index != 0);17     self.nextButton.enabled = (self.index != self.imageData.count - 1);18 }19 20 #pragma mark 上一張21 - (IBAction)previous {22     self.index--;23     [self changeData];24 }25 26 #pragma mark 下一張27 - (IBAction)next {28     self.index++;29     [self changeData];30 }31 @end
  

[iOS基礎控制項 - 3.3] 圖片瀏覽器

聯繫我們

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