05-图片浏览器

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值