图片浏览器代码
2015-08-16 09:36
330 查看
// // ViewController.m // photoexplorer_test1 // // Created by administrator on 15/8/4. // Copyright (c) 2015年 gengcong. All rights reserved. // #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UILabel *contentLabel; @property (weak, nonatomic) IBOutlet UILabel *descLabel; - (IBAction)leftClick:(id)sender; @property (weak, nonatomic) IBOutlet UIButton *leftBtn; - (IBAction)rightClick:(id)sender; @property (weak, nonatomic) IBOutlet UIButton *rightBtn; @property(nonatomic,strong)NSArray *imageData; @property(nonatomic,assign)int index; @property (weak, nonatomic) IBOutlet UIImageView *photoView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.index=0; [self changePhoto]; if (_imageData==nil) { NSBundle *bundle=[NSBundle mainBundle]; NSString *path=[bundle pathForResource:@"photo" ofType:@"plist"]; _imageData=[NSArray arrayWithContentsOfFile:path]; } self.contentLabel.text=[NSString stringWithFormat:@"%d/%lu",self.index+1,(unsigned long)self.imageData.count]; NSDictionary *dic=self.imageData[self.index]; NSString *name=dic[@"icon"]; NSString *desc=dic[@"desc"]; self.photoView.image=[UIImage imageNamed:name]; self.descLabel.text=desc; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)changePhoto { self.contentLabel.text=[NSString stringWithFormat:@"%d/%lu",self.index+1,(unsigned long)self.imageData.count]; NSDictionary *dic=self.imageData[self.index]; // NSString *name=dic[@"icon"]; NSString *desc=dic[@"desc"]; self.photoView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%d",self.index+1]]; self.descLabel.text=desc; BOOL Isfirst=NO; BOOL Islast=NO; if (self.index==0) { Isfirst=YES; } if (self.index==self.imageData.count-1) { Islast=YES; } if (Isfirst) { self.leftBtn.enabled=NO; } else self.leftBtn.enabled=YES; if (Islast) { self.rightBtn.enabled=NO; } else self.rightBtn.enabled=YES; } - (IBAction)leftClick:(id)sender { self.index--; [self changePhoto]; } - (IBAction)rightClick:(id)sender { self.index++; [self changePhoto]; } @end
相关文章推荐
- Raspberry PI语音控制-PocketSphinx
- 简述Java内存泄露
- 汤姆猫代码实现
- C语言基础
- 深入解析C语言中的内存分配相关问题
- Socket编程系列
- VC++数据类型转换大全
- Qt 中update()和repaint()的区别
- c++面试总结
- 《Java设计模式》七大原则
- 《Java设计模式》之接口模式
- 利用Visual Studio寻找C#程序必要的运行库文件
- java工具类(七)实现给定任意年份和月份得出天数
- java工具类(七)实现给定任意年份和月份得出天数
- (转)C#生成中文汉字验证码源码(webform)
- Java进阶(十四)实现每天定时对数据库的操作
- Java进阶(十四)实现每天定时对数据库的操作
- C语言scanf()和gets()及printf()和puts()的区别
- JAVA 注解的几大作用及使用方法详解
- Java进阶(十三)servlet监听器