您的位置:首页 > 移动开发 > IOS开发

05-图片浏览器

2016-01-17 13:16 295 查看
05-图片浏览器 源码下载

//
//  ViewController.m
//  05-图片浏览器
//
//  Created by yibooo on 16/1/17.
//  Copyright © 2016年 yibooo. All rights reserved.
//

/*
strong: 一般对象
weak: UI 控件
*/

#define kIconKey @"icon"

#import "ViewController.h"

@interface ViewController ()

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

//索引标签
@property (weak, nonatomic) IBOutlet UILabel *indexLabel;

// 图像数据
@property (nonatomic, strong) NSArray *imageArray;

// 图像控件
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

// 图像描述
@property (weak, nonatomic) IBOutlet UILabel *dscView;

// 上一张按钮控件
@property (weak, nonatomic) IBOutlet UIButton *preBtn;

// 下一张按钮控件
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;

// 上一张按钮
- (IBAction)previous;

// 下一张按钮
- (IBAction)next;

@end

@implementation ViewController

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

// UILable 自动换行
self.dscView.numberOfLines = 0;
// 设置索引标签的初始显示的值
[self changeData];
}

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

// 使用的时候才去加载,懒加载
- (NSArray *) imageArray{
//    第一次加载的时候
if (_imageArray == nil) {
// NSBundle 应用所在的文件夹
// 获取plist的全路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"imageData" ofType:@"plist"];
// 只要是方法名后面是File,那么就需要全路径
_imageArray = [NSArray arrayWithContentsOfFile:path];
}

return _imageArray;
}
- (void) changeData{
//    设置索引文本
self.indexLabel.text = [NSString stringWithFormat:@"%d/%lu", self.index + 1, (unsigned long)self.imageArray.count];

//    取出索引对应的字典
NSDictionary *dict = self.imageArray[self.index];

//    改变图片
self.imageView.image = [UIImage imageNamed:dict[kIconKey]];

//    改变图片描述
self.dscView.text = dict[@"desc"];

self.preBtn.enabled = (self.index != 0);

self.nextBtn.enabled = (self.index != self.imageArray.count - 1);
}

- (IBAction)previous {
self.index--;

[self changeData];
}

- (IBAction)next {
self.index++;

[self changeData];
}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  IOS-相册-图片