图片浏览器代码

 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

 

转载于:https://www.cnblogs.com/gc1991/p/4733644.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值