//

//  ViewController.m

//  19-图片浏览器

//

//  Created by hongqiangli on 2017/7/31.

//  Copyright © 2017年 李洪强. All rights reserved.

//

#define icon @"icon"

#define desc @"desc"

#import "ViewController.h"

@interface ViewController ()

/**

记录当前的索引号

*/

@property(nonatomic,assign)int index;

/**

上一张

*/

- (IBAction)previous;

/**

下一张

*/

- (IBAction)next;

/**

描述

*/

@property (weak, nonatomic) IBOutlet UILabel *descLabel;

/**

上一个按钮

*/

@property (weak, nonatomic) IBOutlet UIButton *previousBtn;

/**

下一个按钮

*/

@property (weak, nonatomic) IBOutlet UIButton *nextBtn;

/**

索引label

*/

@property (weak, nonatomic) IBOutlet UILabel *noLabel;

@property (weak, nonatomic) IBOutlet UIImageView *mainImageView;

/**

一般的OC对象用strong修饰

*/

@property(nonatomic,strong)NSArray *images;

@end

@implementation ViewController

- (NSArray *)images{

if(_images == nil){

//字典的方式初始化

//        NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];

//        dic1[icon] = @"biaoqingdi";

//        dic1[desc] = @"在他面前,其他神马表情都弱爆了!";

//        NSMutableDictionary *dict2 = [NSMutableDictionary dictionary];

//        dict2[icon]=  @"wangba" ;

//        dict2[desc] = @"哥们为什么选八号呢";

//        NSMutableDictionary *dict3 = [NSMutableDictionary dictionary];

//        dict3[icon]=  @"bingli" ;

//        dict3[desc] = @"这也忒狠了!";

//        NSMutableDictionary *dict4 = [NSMutableDictionary dictionary];

//        dict4[icon]=  @"chiniupa" ;

//        dict4[desc] = @"这小姑娘吃个牛排比杀牛还费劲啊";

//        NSMutableDictionary *dict5 = [NSMutableDictionary dictionary];

//        dict5[icon]=  @"danteng" ;

//        dict5[desc] = @"亲,你能改下你的网名么?哈哈";

//        _images = @[dic1,dict2,dict3,dict4,dict5];

//用plist的方式加载

//拿到plist文件的全路径

NSString *path = [[NSBundle mainBundle]pathForResource:@"images" ofType:@"plist"];

_images = [NSArray arrayWithContentsOfFile:path];

}

return _images;

}

- (void)viewDidLoad {

[super viewDidLoad];

[self changData];

}

/**

点击上一张

*/

- (IBAction)previous {

_index--;

[self changData];

}

/**

下一张

*/

- (IBAction)next {

_index++;

[self changData];

}

- (void)changData{

_noLabel.text = [NSString stringWithFormat:@"%d/%ld",_index + 1,_images.count];

NSDictionary *dict = _images[_index];

NSString *iconStr = dict[icon];

NSString *descStr = dict[desc];

_mainImageView.image = [UIImage imageNamed:iconStr];

_descLabel.text = descStr;

//判断按钮能不能点击

_previousBtn.enabled = (_index != 0);

_nextBtn.enabled = (_index != 4);

}

@end

iOS-图片浏览器(字典和plist文件的使用)的更多相关文章

  1. iOS 打包.framework(包括第三方、图片、xib、plist文件)详细步骤及需要注意的地方

    https://www.cnblogs.com/yk123/p/9340268.html // 加载自定义名称为Resources.bundle中对应images文件夹中的图片// 思路:从mainb ...

  2. iOS边练边学--plist文件,懒加载,模型初使用--补充instancetype

    一.什么是plist文件 1>将数据直接写在代码里面,不是一种合理的做法.如果数据经常修改,就要经常翻开对应的代码进行修改,造成代码扩展性低 2>因此,可以考虑将经常变得数据放在文件中进行 ...

  3. IOS学习笔记之获取Plist文件读取数据

    @property(nonatomic,strong) NSArray *pic; //创建数组属性 @property(nonatomic,assign) int index; //创建索引属性 @ ...

  4. 【IOS】iOS 企业版应用网站下载plist文件

    如果想从自己公司的网站上下载安装应用,首先 准备一个 index.html文件 <!DOCTYPE html> <html lang="zh-cn"> &l ...

  5. iOS 网络请求--- 配置info.plist文件

    一.配置info.plist <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitra ...

  6. iOS工程中的info.plist文件的完整研究

    原地址:http://blog.sina.com.cn/s/blog_947c4a9f0100zf41.html 们建立一个工程后,会在Supporting files下面看到一个"工程名- ...

  7. IOS 读取本地的Json/plist 文件

    一.一般本地可以存储轻量级数据存储 plist  这个主要是操作字典 方法如下: NSString * sampleFile= [[[NSBundle mainBundle] bundlePath] ...

  8. iOS工程中的info.plist文件

    我们建立一个工程后,会在Supporting files下面看到一个"工程名-Info.plist"的文件,这个是对工程做一些运行期配置的文件,很重要,不能删除. 如果你在网上下载 ...

  9. WPF图片浏览器(显示大图、小图等)

    原文:WPF图片浏览器(显示大图.小图等) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wangshubo1989/article/details ...

随机推荐

  1. Qt5中创建临时的后台线程。

    有个需求就是,GUI图形界面在上传文件到服务器的时候,需要用zip命令行打包,因为文件很多的时候,zip命令打包需要计算很长时间,所以把这样计算量大的任务分离到后台线程比较合适,然后任务完成,以信号槽 ...

  2. CPP复习笔记 3

    --------------- CPP函数编译原理和成员函数的实现 从上节的分析中能够看出.对象的内存中仅仅保留了成员变量,除此之外没有不论什么其它信息,程序运行时不知道 stu 的类型为 Stude ...

  3. ios中NSObject分类

    #import <Foundation/Foundation.h> #define BUNDLE_PATH_IMAGENAME(c) [[NSBundle mainBundle] path ...

  4. Windows XPSP3通过网络级身份验证方式连接Windows Server 2008远程桌面

    远程桌面大大方便了大家的日常管理工作,Windows Server 2008同样秉承这一优秀特性,并引入网络级身份验证(NLA)作为远程桌面连接的默认身份验证方式. 网络级身份验证 (NLA) 是一种 ...

  5. std::bind 详解及参数解析

    // Bind_std_function.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> ...

  6. 树莓派进阶之路 (007) - 树莓派安装cmake3.5 脚本(原创)

    cmake3.5安装脚本: #!/bin/bash cd echo "安装make" sudo apt-get install make echo "安装cmake&qu ...

  7. io分析神器blktrace

    一.概述 [许久之前就用过blktrace,现整理如下] 从linux 一个完整的IO入手分析: 一个I/O请求进入block layer之后,可能会经历下面的过程: Remap: 可能被DM(Dev ...

  8. 【struts2】Struts2的异常处理

    在Action中execute方法声明为:public String execute() throws Exception,这样,Action可以抛出任何Exception. 1)自己实现异常处理 我 ...

  9. Android的API版本和名称对应关系

    Android版本名和API Level关系全称 Android的版本 Android版本名称Code name Android的API level Android 1.0 (API level 1) ...

  10. mvc 权限验证

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...