UI基礎篇-iOS中簡單圖片瀏覽器的實現

來源:互聯網
上載者:User

標籤:

  1 //  2   3 //  HYViewController.m  4   5 //  01-圖片瀏覽器複習  6   7 //  8   9 //  Created by apple on 15-4-10. 10  11 //  Copyright (c) 2015年 apple. All rights reserved. 12  13 // 14  15   16  17 #import "HYViewController.h" 18  19   20  21 @interface HYViewController () 22  23 - (IBAction)last; 24  25 - (IBAction)next; 26  27 /**顯示圖片的序號*/ 28  29 @property (weak, nonatomic) IBOutlet UILabel *numlable; 30  31 /**顯示圖片*/ 32  33 @property (weak, nonatomic) IBOutlet UIImageView *myimage; 34  35 /** 顯示圖片的描述*/ 36  37 @property (weak, nonatomic) IBOutlet UILabel *desclable; 38  39 /** 顯示按鈕的狀態*/ 40  41 @property (weak, nonatomic) IBOutlet UIButton *lastbtn; 42  43 @property (weak, nonatomic) IBOutlet UIButton *nextbtn; 44  45   46  47 /** 圖片資料的集合*/ 48  49 @property (nonatomic,strong) NSArray *arrayimage; 50  51 /** 記錄圖片顯示的索引*/ 52  53 @property(nonatomic,assign) int index; 54  55 @end 56  57   58  59 @implementation HYViewController 60  61 /** 資料的懶載入*/ 62  63 -(NSArray *)arrayimage 64  65 { 66  67     if(_arrayimage==nil) 68  69     { 70  71         //第一次載入 72  73         //初始化資料 74  75         //1.利用mainBoundle就可以訪問手機資源套件的任何資源 76  77         NSBundle *bdle=[NSBundle mainBundle]; 78  79         //2.擷取全路徑 80  81        NSString *path=   [bdle pathForResource:@"changeData" ofType:@"plist"]; 82  83         //3. 讀取全路徑下的資源 84  85         _arrayimage=[NSArray arrayWithContentsOfFile:path]; 86  87     } 88  89      90  91     return _arrayimage; 92  93 } 94  95   96  97 //當控制器的view初始化完畢的時候調用該方法 98  99 - (void)viewDidLoad100 101 {102 103     [super viewDidLoad];104 105     [self changeData];106 107 108 }109 110  111 112 /** 資料的改變*/113 114 -(void)changeData115 116 {117 118     //1.改變序號119 120     self.numlable.text=[NSString stringWithFormat:@"%d/%d",self.index+1,self.arrayimage.count];121 122     //2.取出字典數組裡的值  數組名[索引下標]123 124     NSDictionary *dectimage=  self.arrayimage[self.index];125 126     //3.改變圖片127 128     self.myimage.image=[UIImage imageNamed:dectimage[@"icon"]];129 130     //4.改變描述131 132     self.desclable.text=dectimage[@"desc"];133 134     //5.改變按鈕的狀態135 136     self.lastbtn.enabled=(self.index!=0);137 138     self.nextbtn.enabled=(self.index!=self.arrayimage.count-1);139 140 }141 142  143 144 /** 顯示上一張圖片*/145 146 - (IBAction)last147 148 {149 150     self.index--;151 152     [self changeData];153 154     155 156 } 157 158 /** 顯示下一張圖片*/159 160 - (IBAction)next161 162 {163 164     self.index++;165 166     [self changeData];167 168 }169 170 @end171 172 173 174 //個人總結:消極式載入的設計、NSBoundle的使用,plist檔案的使用

 

UI基礎篇-iOS中簡單圖片瀏覽器的實現

聯繫我們

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