//
// ViewController.m
// PromotedImageValley
//
// Created by hq on 16/3/1.
// Copyright :emoji: 2016年 hanqing. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
//保存我们所有的图片信息的数组
@property(strong,nonatomic) NSArray *imgArray;
//表示当前是哪一张图片
@property (weak, nonatomic) IBOutlet UILabel *headerTitle;
//我们的图片对象
@property (weak, nonatomic) IBOutlet UIImageView *imageObj;
//图片下方的描述信息
@property (weak, nonatomic) IBOutlet UILabel *imgDesc;
//切换到下张图片
@property (weak, nonatomic) IBOutlet UIButton *nextBut;
//切换到上一张图片
@property (weak, nonatomic) IBOutlet UIButton *preBut;
@property (assign,nonatomic) int currentIndex;
- (IBAction)previous;
- (IBAction)next;
@end
@implementation ViewController
//重写我们imgArray的get方法
-(NSArray *)imgArray{
//通过懒加载到方式读取我们plist中的内容
if (_imgArray==nil) {
//读取我们的plist当中的图片对象
/*
首先获取我们的plist在手机中的文件路径,nsstring类型
NSBundle mainBundle表示获取到这个app安装到手机上时的根目录
*/
NSString *path=[[NSBundle mainBundle] pathForResource:@"imageObj.plist" ofType:nil];
//NSLog(@"%@",path);
//取出plist当中的内容,赋值给我们的imgArray
self.imgArray=[NSArray arrayWithContentsOfFile:path];
}
return _imgArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
//默认为第一张图片
self.currentIndex=0;
[self setData:self.currentIndex];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
//上一张图片
- (IBAction)previous {
[self setData:--self.currentIndex];
}
//下一张图片
- (IBAction)next {
[self setData:++self.currentIndex];
}
//写一个设置数值的方法
-(void) setData:(int) currentIndex{
if (currentIndex<=0) {
self.preBut.enabled=NO;
}
else if (currentIndex>=self.imgArray.count-1) {
self.nextBut.enabled=NO;
}
else{
self.preBut.enabled=YES;
self.nextBut.enabled=YES;
}
NSDictionary *dict=self.imgArray[currentIndex];
self.imageObj.image=[UIImage imageNamed:dict[@"imgName"]];
self.headerTitle.text=[NSString stringWithFormat:@"%d/%ld",currentIndex+1,self.imgArray.count];
self.imgDesc.text=dict[@"imgDesc"];
}
@end
// ViewController.m
// PromotedImageValley
//
// Created by hq on 16/3/1.
// Copyright :emoji: 2016年 hanqing. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
//保存我们所有的图片信息的数组
@property(strong,nonatomic) NSArray *imgArray;
//表示当前是哪一张图片
@property (weak, nonatomic) IBOutlet UILabel *headerTitle;
//我们的图片对象
@property (weak, nonatomic) IBOutlet UIImageView *imageObj;
//图片下方的描述信息
@property (weak, nonatomic) IBOutlet UILabel *imgDesc;
//切换到下张图片
@property (weak, nonatomic) IBOutlet UIButton *nextBut;
//切换到上一张图片
@property (weak, nonatomic) IBOutlet UIButton *preBut;
@property (assign,nonatomic) int currentIndex;
- (IBAction)previous;
- (IBAction)next;
@end
@implementation ViewController
//重写我们imgArray的get方法
-(NSArray *)imgArray{
//通过懒加载到方式读取我们plist中的内容
if (_imgArray==nil) {
//读取我们的plist当中的图片对象
/*
首先获取我们的plist在手机中的文件路径,nsstring类型
NSBundle mainBundle表示获取到这个app安装到手机上时的根目录
*/
NSString *path=[[NSBundle mainBundle] pathForResource:@"imageObj.plist" ofType:nil];
//NSLog(@"%@",path);
//取出plist当中的内容,赋值给我们的imgArray
self.imgArray=[NSArray arrayWithContentsOfFile:path];
}
return _imgArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
//默认为第一张图片
self.currentIndex=0;
[self setData:self.currentIndex];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
//上一张图片
- (IBAction)previous {
[self setData:--self.currentIndex];
}
//下一张图片
- (IBAction)next {
[self setData:++self.currentIndex];
}
//写一个设置数值的方法
-(void) setData:(int) currentIndex{
if (currentIndex<=0) {
self.preBut.enabled=NO;
}
else if (currentIndex>=self.imgArray.count-1) {
self.nextBut.enabled=NO;
}
else{
self.preBut.enabled=YES;
self.nextBut.enabled=YES;
}
NSDictionary *dict=self.imgArray[currentIndex];
self.imageObj.image=[UIImage imageNamed:dict[@"imgName"]];
self.headerTitle.text=[NSString stringWithFormat:@"%d/%ld",currentIndex+1,self.imgArray.count];
self.imgDesc.text=dict[@"imgDesc"];
}
@end
2730

被折叠的 条评论
为什么被折叠?



