标签:
--------------- ViewController.m ---------------
#import <Foundation/Foundation.h>
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *indexLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;
@property (nonatomic, assign) int index;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;
@property (nonatomic, strong) NSArray *datas;
- (IBAction)nextImage;
- (IBAction)preImage;
-(void)changeImage;
@end
@implementation ViewController
-(void)viewDidLoad
{
[super viewDidLoad];
[self nextImage];
}
-(NSArray *)datas
{
if (_datas == nil)
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"imageData" ofType:@"plist"];
_datas = [NSArray arrayWithContentsOfFile:path];
}
return _datas;
}
-(void)changeImage
{
self.indexLabel.text = [NSString stringWithFormat:@"%d/%zd",self.index, self.datas.count];
NSDictionary *data = self.datas[self.index-1];
self.imageView.image = [UIImage imageNamed:data[@"icon"]];
self.infoLabel.text = data[@"desc"];
self.leftBtn.enabled = self.index != 1;
self.rightBtn.enabled = self.index != self.datas.count;
}
- (IBAction)nextImage
{
self.index++;
[self changeImage];
}
- (IBAction)preImage
{
self.index--;
[self changeImage];
}
@end
标签:
原文地址:http://www.cnblogs.com/lixiang2015/p/4695265.html