//
// ViewController.m
// 19-图片浏览器
//
// Created by hongqiangli on 2017/7/31.
// Copyright © 2017年 李洪强. All rights reserved.
//
#define icon @"icon"
#define desc @"desc"
#import "ViewController.h"
@interface ViewController ()
/**
记录当前的索引号
*/
@property(nonatomic,assign)int index;
/**
上一张
*/
- (IBAction)previous;
/**
下一张
*/
- (IBAction)next;
/**
描述
*/
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
/**
上一个按钮
*/
@property (weak, nonatomic) IBOutlet UIButton *previousBtn;
/**
下一个按钮
*/
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;
/**
索引label
*/
@property (weak, nonatomic) IBOutlet UILabel *noLabel;
@property (weak, nonatomic) IBOutlet UIImageView *mainImageView;
/**
一般的OC对象用strong修饰
*/
@property(nonatomic,strong)NSArray *images;
@end
@implementation ViewController
- (NSArray *)images{
if(_images == nil){
//字典的方式初始化
// NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];
// dic1[icon] = @"biaoqingdi";
// dic1[desc] = @"在他面前,其他神马表情都弱爆了!";
// NSMutableDictionary *dict2 = [NSMutableDictionary dictionary];
// dict2[icon]= @"wangba" ;
// dict2[desc] = @"哥们为什么选八号呢";
// NSMutableDictionary *dict3 = [NSMutableDictionary dictionary];
// dict3[icon]= @"bingli" ;
// dict3[desc] = @"这也忒狠了!";
// NSMutableDictionary *dict4 = [NSMutableDictionary dictionary];
// dict4[icon]= @"chiniupa" ;
// dict4[desc] = @"这小姑娘吃个牛排比杀牛还费劲啊";
// NSMutableDictionary *dict5 = [NSMutableDictionary dictionary];
// dict5[icon]= @"danteng" ;
// dict5[desc] = @"亲,你能改下你的网名么?哈哈";
// _images = @[dic1,dict2,dict3,dict4,dict5];
//用plist的方式加载
//拿到plist文件的全路径
NSString *path = [[NSBundle mainBundle]pathForResource:@"images" ofType:@"plist"];
_images = [NSArray arrayWithContentsOfFile:path];
}
return _images;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self changData];
}
/**
点击上一张
*/
- (IBAction)previous {
_index--;
[self changData];
}
/**
下一张
*/
- (IBAction)next {
_index++;
[self changData];
}
- (void)changData{
_noLabel.text = [NSString stringWithFormat:@"%d/%ld",_index + 1,_images.count];
NSDictionary *dict = _images[_index];
NSString *iconStr = dict[icon];
NSString *descStr = dict[desc];
_mainImageView.image = [UIImage imageNamed:iconStr];
_descLabel.text = descStr;
//判断按钮能不能点击
_previousBtn.enabled = (_index != 0);
_nextBtn.enabled = (_index != 4);
}
@end