//
// ViewController.m
// 图片浏览器
//
// Created by 罗普生 on 14/12/4.
// Copyright (c) 2014年 luopusheng. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
- (IBAction)change:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UILabel *top;
@property (weak, nonatomic) IBOutlet UIImageView *show;
@property (weak, nonatomic) IBOutlet UILabel *dwon;
@property (weak, nonatomic) IBOutlet UIButton *left;
@property (weak, nonatomic) IBOutlet UIButton *right;
@property (nonatomic,assign) int index;
@property (nonatomic,strong) NSArray *imgDate;
@end
@implementation ViewController
-(void)viewDidLoad{
[super viewDidLoad];
//初始化数据
NSMutableDictionary *img1 = [NSMutableDictionary dictionary];
img1[@"icon"] = @"biaoqingdi";
img1[@"desc"] = @"拐子,又扯到蛋了?";
NSMutableDictionary *img2 = [NSMutableDictionary dictionary];
img2[@"icon"] = @"wangba";
img2[@"desc"] = @"大锤,为什么选8号?";
NSMutableDictionary *img3 = [NSMutableDictionary dictionary];
img3[@"icon"] = @"bingli";
img3[@"desc"] = @"这也太狠了!";
NSMutableDictionary *img4 = [NSMutableDictionary dictionary];
img4[@"icon"] = @"chiniupa";
img4[@"desc"] = @"哎,真费劲!";
NSMutableDictionary *img5 = [NSMutableDictionary dictionary];
img5[@"icon"] = @"danteng";
img5[@"desc"] = @"~~~~";
_imgDate = [NSArray arrayWithObjects:img1, img2, img3,img4,img5, nil];
[self changeDate];
}
#pragma mark changDate
-(void)changeDate{
//改变数据
_top.text = [NSString stringWithFormat:@"%d/%lu",_index + 1,self.imgDate.count];
//取出index对应的字典数据
NSDictionary *imaDic = _imgDate[_index];
NSLog(@"%d-------------,%@",_index,imaDic);
//设置图片
_show.image = [UIImage imageNamed:imaDic[@"icon"]];
//设置描述
_dwon.text = imaDic[@"desc"];
//设置按钮状态
_left.enabled = _index != 0;
_right.enabled = _index != _imgDate.count - 1;
}
- (IBAction)change:(UIButton *)sender {
switch (sender.tag) {
case 1:
_index --;
[self changeDate];
break;
default:
_index ++;
[self changeDate];
break;
}
}
@end