1 // 2 // ViewController.m 3 // photoexplorer_test1 4 // 5 // Created by administrator on 15/8/4. 6 // Copyright (c) 2015年 gengcong. All rights reserved. 7 // 8 9 #import "ViewController.h" 10 11 @interface ViewController () 12 @property (weak, nonatomic) IBOutlet UILabel *contentLabel; 13 @property (weak, nonatomic) IBOutlet UILabel *descLabel; 14 - (IBAction)leftClick:(id)sender; 15 @property (weak, nonatomic) IBOutlet UIButton *leftBtn; 16 - (IBAction)rightClick:(id)sender; 17 @property (weak, nonatomic) IBOutlet UIButton *rightBtn; 18 @property(nonatomic,strong)NSArray *imageData; 19 @property(nonatomic,assign)int index; 20 @property (weak, nonatomic) IBOutlet UIImageView *photoView; 21 @end 22 23 @implementation ViewController 24 25 - (void)viewDidLoad { 26 [super viewDidLoad]; 27 self.index=0; 28 [self changePhoto]; 29 if (_imageData==nil) { 30 NSBundle *bundle=[NSBundle mainBundle]; 31 NSString *path=[bundle pathForResource:@"photo" ofType:@"plist"]; 32 _imageData=[NSArray arrayWithContentsOfFile:path]; 33 } 34 self.contentLabel.text=[NSString stringWithFormat:@"%d/%lu",self.index+1,(unsigned long)self.imageData.count]; 35 NSDictionary *dic=self.imageData[self.index]; 36 NSString *name=dic[@"icon"]; 37 NSString *desc=dic[@"desc"]; 38 self.photoView.image=[UIImage imageNamed:name]; 39 self.descLabel.text=desc; 40 } 41 42 43 44 45 46 - (void)didReceiveMemoryWarning { 47 [super didReceiveMemoryWarning]; 48 // Dispose of any resources that can be recreated. 49 } 50 51 52 53 -(void)changePhoto 54 { 55 self.contentLabel.text=[NSString stringWithFormat:@"%d/%lu",self.index+1,(unsigned long)self.imageData.count]; 56 NSDictionary *dic=self.imageData[self.index]; 57 // NSString *name=dic[@"icon"]; 58 NSString *desc=dic[@"desc"]; 59 self.photoView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%d",self.index+1]]; 60 self.descLabel.text=desc; 61 BOOL Isfirst=NO; 62 BOOL Islast=NO; 63 if (self.index==0) { 64 Isfirst=YES; 65 } 66 if (self.index==self.imageData.count-1) { 67 Islast=YES; 68 } 69 if (Isfirst) { 70 self.leftBtn.enabled=NO; 71 } 72 else self.leftBtn.enabled=YES; 73 if (Islast) { 74 self.rightBtn.enabled=NO; 75 76 } 77 else self.rightBtn.enabled=YES; 78 79 80 81 82 83 84 85 86 87 } 88 89 - (IBAction)leftClick:(id)sender { 90 self.index--; 91 [self changePhoto]; 92 93 } 94 - (IBAction)rightClick:(id)sender { 95 self.index++; 96 [self changePhoto]; 97 } 98 @end