Objective-C ,ios,iphone开发基础:快速实现一个简单的图片查看器
新建一个single view 工程:
关闭ARC , 在.xib视图文件上拖放一个UIImageView 两个UIButton ,一个UISlider ,布局如图。
并为他们连线,
UIImageView 和 UISlider 分别定义插座变量,两个 UIButton 分别 连接两个Action next和previous ,在为 UISlider 连接一个Action 事件。
再在.h 文件中声明两个实例变量。 NSInteger index ; NSMutableArray* arrayPic ; 一个用来记录当前图片的index,一个用来做图片的容器,
用UISlider 来控制图片的透明度 (alpha 属性)。在slider 的界面构建起动作中添加代码,让图片的透明度等于 slider的value。
- (IBAction)sliderChangeValued:(id)sender { self.imageView.alpha = slider.value;
}
在两个UIButton 的界面构建起动作中添加代码,循环遍历arrayPic中的图片:
- (IBAction)next:(id)sender {
if(index == [arrayPic count]){
index = ;
}
self.imageView.image = [UIImage imageWithContentsOfFile:[arrayPic objectAtIndex:index]];
index++;
} - (IBAction)previous:(id)sender {
if(index == -){
index = ([arrayPic count] -);
}
self.imageView.image = [UIImage imageWithContentsOfFile:[arrayPic objectAtIndex:index]];
index--;
}
至此:简单的图片查看器已经完成,
整个控制器类中的代码:
//
// wsqViewController.h
// picLook
//
// Created by administrator on 13-9-5.
// Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
// #import <UIKit/UIKit.h> @interface wsqViewController : UIViewController {
UIImageView *imageView;
UISlider *slider;
NSInteger index ;
NSMutableArray* arrayPic ; } @property (retain, nonatomic) IBOutlet UIImageView *imageView;
@property (retain, nonatomic) IBOutlet UISlider *slider;
- (IBAction)sliderChangeValued:(id)sender;
- (IBAction)next:(id)sender; - (IBAction)previous:(id)sender; @end
//
// wsqViewController.m
// picLook
//
// Created by administrator on 13-9-5.
// Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
// #import "wsqViewController.h" @implementation wsqViewController
@synthesize imageView;
@synthesize slider; - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
} #pragma mark - View lifecycle - (void)viewDidLoad
{
[super viewDidLoad];
//获取mainbudle下所有 jpg格式的图片,
arrayPic = [[NSMutableArray alloc ] initWithArray: [[NSBundle mainBundle] pathsForResourcesOfType:@"jpg" inDirectory:nil]];
index = ;
NSLog(@"%@",arrayPic); } - (void)viewDidUnload
{
[self setImageView:nil];
[self setSlider:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
} - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
} - (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
} - (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
} - (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
} - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} - (void)dealloc {
[arrayPic release];
[imageView release];
[slider release];
[super dealloc];
}
- (IBAction)sliderChangeValued:(id)sender { self.imageView.alpha = slider.value;
} - (IBAction)next:(id)sender {
if(index == [arrayPic count]){
index = ;
}
self.imageView.image = [UIImage imageWithContentsOfFile:[arrayPic objectAtIndex:index]];
index++;
} - (IBAction)previous:(id)sender {
if(index == -){
index = ([arrayPic count] -);
}
self.imageView.image = [UIImage imageWithContentsOfFile:[arrayPic objectAtIndex:index]];
index--;
}
@end
Objective-C ,ios,iphone开发基础:快速实现一个简单的图片查看器的更多相关文章
- iOS开发-简单的图片查看器
现在你只要拿着手机,不管你Android还是iOS,新闻类的App不可避免都有一个功能就是图片查看,做个专题,查看一下内容,App Store中也有专门针对图片浏览的App,鉴于目前所知有限,无法做到 ...
- [置顶] Objective-C ,ios,iphone开发基础:UIAlertView使用详解
UIAlertView使用详解 Ios中为我们提供了一个用来弹出提示框的类 UIAlertView,他类似于javascript中的alert 和c#中的MessageBox(); UIAlertVi ...
- Objective-C ,ios,iphone开发基础:UIAlertView使用详解
UIAlertView使用详解 Ios中为我们提供了一个用来弹出提示框的类 UIAlertView,他类似于javascript中的alert 和c#中的MessageBox(); UIAlertVi ...
- Objective-C ,ios,iphone开发基础:使用GDataXML解析XML文档,(libxml/tree.h not found 错误解决方案)
使用GDataXML解析XML文档 在IOS平台上进行XML文档的解析有很多种方法,在SDK里面有自带的解析方法,但是大多情况下都倾向于用第三方的库,原因是解析效率更高.使用上更方便 这里主要介绍一下 ...
- Objective-C ,ios,iphone开发基础:picker控件详解与使用,(实现省市的二级联动)
第一步:新建一个单视图(single view)的工程, 命名为pickerTest,不要勾选下面两个选项,第一个是新版本里面的,第二个是单元测试,现在用不着. 点击next ->creat之 ...
- Objective-C ,ios,iphone开发基础:几个常用类-NSNumber
2013-08-21 在Objective-C,包括int double float 等等再内的基础数据类型都不是一个类,所以就不能给它们发送消息,也就是说不能调用方法,那怎么办呢 ?Objectiv ...
- Objective-C ,ios,iphone开发基础:JSON解析(使用苹果官方提供的JSON库:NSJSONSerialization)
json和xml的普及个人觉得是为了简化阅读难度,以及减轻网络负荷,json和xml 数据格式在格式化以后都是一种树状结构,可以树藤摸瓜的得到你想要的任何果子. 而不格式化的时候json和xml 又是 ...
- Objective-C ,ios,iphone开发基础:http网络编程
- (IBAction)loadData:(id)sender { NSURL* url = [NSURL URLWithString:@"http://162.105.65.251:808 ...
- Objective-C ,ios,iphone开发基础:3分钟教你做一个iphone手机浏览器
第一步:新建一个Single View工程: 第二步:新建好工程,关闭arc. 第三步:拖放一个Text Field 一个UIButton 和一个 UIWebView . Text Field 的ti ...
随机推荐
- 第二百四十一天 how can I 坚持
今天去了趟小米之家,红米note3感觉还好吧.小米,希望不会令人失望啊,很看好的,应该不算是米粉吧. 腾讯课堂. hadoop. 摄影. 没有真正的兴趣啊,一心只想着玩,什么事真正的兴趣,就是无时无刻 ...
- SpringMVC 避免IE执行AJAX时,返回JSON出现下载文件
<?xml version="1.0" encoding="UTF-8"?> <!-- SpringMVC配置文件 --> <be ...
- linux中vi编辑器
vi编辑器,通常称之为vi,是一种广泛存在于各种UNIX和Linux系 统中的文本编辑程序.它的功能十分强大,但是命令繁多,不容易掌握,它可以执行输出.删除.查找.替换.块操作等众多文本操作,而且用户 ...
- thinkPHP模板的输出和模型的使用
a.通过 echo 等PHP原生的输出方式在页面中输出 b.通过display方法输出 想分配变量可以使用assign方法 c.修改左右定界符 休要修改配置文件中的配置项 'TMPL_L_DELIM' ...
- Nexus搭建Manven
Nexus相当于中转服务器,减轻网络的负载,加速项目搭建的进程 1.下载地址:http://www.sonatype.org/nexus/go 2.下载的是zip包,解压后进入D:\nexus-2.8 ...
- OpenNebula config配置详情
AUTH_MAD=AUTHN=ssh,x509,ldap,server_cipher,server_x509,EXECUTABLE=one_auth_mad DATASTORE_BASE_PATH=/ ...
- 从hello-world 开始 <contiki学习之四>
按照contiki 官方给出的example下的例子之hello world来说,所有的工程里面都有一个唯一的Makefile.然后这个Makefile会去调用其他makefile文件.于是,一切就从 ...
- C# - 函数参数的传递
近段时间,有几个刚刚开始学习C#语言的爱好者问我:C#中的函数,其参数的传递,按值传递和按引用传递有什么区别.针对这一问题,我简单写了个示例程序,用以讲解,希望我没有把他们绕晕.因为,常听别人说起:“ ...
- tomcat配置虚拟主机
在眼下,非常多server都是一台server对外能够訪问非常多个javaEE的项目,这样的实现方式就须要在tomcat里面配置虚拟主机了!以下就说说怎样配置虚拟主机: 找到tomcat的安装文件夹, ...
- js中substr与substring的差别
Js的substring和C#的Substring的作用都是从一个字符串中截取出一个子字符串,但它们的用法却有非常大的不同,下边我们来比較看看: Js的substring 语法: 程序代码 S ...