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开发之Masonry(一)
- iOS多线程GCD的简单使用
- 开始学习IOS
- IOS日期处理
- IOS日期的处理
- iOS-MapKit的使用笔记
- iOS中frame与bounds的区别
- IOS视图控制对象生命周期
- edgesForExtendedLayout ios7新特性
- iOS屏幕适配教程(手动布局和自动布局)
- iOS-地图定位 && 解码与反解码
- iOS中计算文本高度
- IOS 开发之_二维码生成与识别
- 【iOS之runtime、runloop】
- iOS开发多线程篇—GCD介绍
- 蓝懿ios技术交流和心得分享16.1.16
- 【iOS开发】CoreText的使用(1)
- iOS-程序启动原理
- iOS视图控制器总结
- iOS移动开发多线程—GCD介绍