iOS-图片浏览器(字典和plist文件的使用)
//
// 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文件的使用)的更多相关文章
- iOS 打包.framework(包括第三方、图片、xib、plist文件)详细步骤及需要注意的地方
https://www.cnblogs.com/yk123/p/9340268.html // 加载自定义名称为Resources.bundle中对应images文件夹中的图片// 思路:从mainb ...
- iOS边练边学--plist文件,懒加载,模型初使用--补充instancetype
一.什么是plist文件 1>将数据直接写在代码里面,不是一种合理的做法.如果数据经常修改,就要经常翻开对应的代码进行修改,造成代码扩展性低 2>因此,可以考虑将经常变得数据放在文件中进行 ...
- IOS学习笔记之获取Plist文件读取数据
@property(nonatomic,strong) NSArray *pic; //创建数组属性 @property(nonatomic,assign) int index; //创建索引属性 @ ...
- 【IOS】iOS 企业版应用网站下载plist文件
如果想从自己公司的网站上下载安装应用,首先 准备一个 index.html文件 <!DOCTYPE html> <html lang="zh-cn"> &l ...
- iOS 网络请求--- 配置info.plist文件
一.配置info.plist <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitra ...
- iOS工程中的info.plist文件的完整研究
原地址:http://blog.sina.com.cn/s/blog_947c4a9f0100zf41.html 们建立一个工程后,会在Supporting files下面看到一个"工程名- ...
- IOS 读取本地的Json/plist 文件
一.一般本地可以存储轻量级数据存储 plist 这个主要是操作字典 方法如下: NSString * sampleFile= [[[NSBundle mainBundle] bundlePath] ...
- iOS工程中的info.plist文件
我们建立一个工程后,会在Supporting files下面看到一个"工程名-Info.plist"的文件,这个是对工程做一些运行期配置的文件,很重要,不能删除. 如果你在网上下载 ...
- WPF图片浏览器(显示大图、小图等)
原文:WPF图片浏览器(显示大图.小图等) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wangshubo1989/article/details ...
随机推荐
- android.database.sqlite.SQLiteException: near "FROM"
07-20 00:19:30.496: E/JavaBinder(6807): *** Uncaught remote exception! (Exceptions are not yet su ...
- 转:Spring Cache抽象详解
缓存简介 缓存,我的理解是:让数据更接近于使用者:工作机制是:先从缓存中读取数据,如果没有再从慢速设备上读取实际数据(数据也会存入缓存):缓存什么:那些经常读取且不经常修改的数据/那些昂贵(CPU/I ...
- mysql my.cnf 配置建议
mysql的配置文件是/etc/my.cnf,通过修改它来配置mysql. /etc/my.cnf来自以下文件: 如果你的内存≤64M,则复制/usr/local/share/mysql/my-sma ...
- SaltStack入门到精通第一篇:安装SaltStack
SaltStack入门到精通第一篇:安装SaltStack 作者:纳米龙 发布日期:2014-06-09 17:50:36 实际环境的设定: 系统环境: centos6 或centos5 实验机 ...
- Map的有序和无序实现类,与Map的排序
1.HashMap.Hashtable不是有序的: 2.TreeMap和LinkedHashMap是有序的(TreeMap默认 Key 升序,LinkedHashMap则记录了插入顺序). 今天做统计 ...
- SpringBoot配置属性之Migration
SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...
- JAVA基本值类型
Java定义了8个简单(或基本)的数据类型:------------------------------------------------------字节型(byte),短整型(short),整型( ...
- 【jQuery】jquery插件封装
扩展jQuery插件开发的基本知识,最佳做法和常见的陷阱. 入门 编写一个jQuery插件开始于给jQuery.fn加入新的功能属性,此处添加的对象属性的名称就是你插件的名称: jQuery.fn ...
- 【Linux】字符转换命令col
[root@www ~]# col [-xb] 选项与参数: -x :将 tab 键转换成对等的空格键 -b :过滤掉所有的控制字符,包括RLF(Reverse Line Feed)和HRF(Halt ...
- Tensorflow中的run()函数
1 run()函数存在的意义 run()函数可以让代码变得更加简洁,在搭建神经网络(一)中,经历了数据集准备.前向传播过程设计.损失函数及反向传播过程设计等三个过程,形成计算网络,再通过会话tf.Se ...