图片浏览器

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;

@property (nonatomic, assign) int index;    // 索引

@property (nonatomic, strong) NSArray *imageDicts;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (NSArray *)imageDicts{
    if (!_imageDicts) {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"imageDate.plist" ofType:nil];
        _imageDicts = [NSArray arrayWithContentsOfFile:path];
    }
    
    return _imageDicts;
}
- (IBAction)leftBtnOnClick:(id)sender {
    self.index--;
    [self btnClickChange];
}
- (IBAction)rightBtnOnClick:(id)sender {
    self.index++;
    [self btnClickChange];
}

- (void)btnClickChange{
    
    // 改变topLabel
    self.titleLabel.text = [NSString stringWithFormat:@"%d/%d",(self.index +1),self.imageDicts.count];
    self.detailLabel.text = self.imageDicts[self.index][@"description"];
    self.imageView.image = [UIImage imageNamed:self.imageDicts[self.index][@"name"]];
    
    self.leftBtn.enabled = (self.index != 0);
    self.rightBtn.enabled = (self.index != self.imageDicts.count - 1);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end```


![pictureBrower1.gif](http://upload-images.jianshu.io/upload_images/189984-b8824f9b3c8f5299.gif?imageMogr2/auto-orient/strip)

你可能感兴趣的:(图片浏览器)