新建一个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开发基础:快速实现一个简单的图片查看器的更多相关文章

  1. iOS开发-简单的图片查看器

    现在你只要拿着手机,不管你Android还是iOS,新闻类的App不可避免都有一个功能就是图片查看,做个专题,查看一下内容,App Store中也有专门针对图片浏览的App,鉴于目前所知有限,无法做到 ...

  2. [置顶] Objective-C ,ios,iphone开发基础:UIAlertView使用详解

    UIAlertView使用详解 Ios中为我们提供了一个用来弹出提示框的类 UIAlertView,他类似于javascript中的alert 和c#中的MessageBox(); UIAlertVi ...

  3. Objective-C ,ios,iphone开发基础:UIAlertView使用详解

    UIAlertView使用详解 Ios中为我们提供了一个用来弹出提示框的类 UIAlertView,他类似于javascript中的alert 和c#中的MessageBox(); UIAlertVi ...

  4. Objective-C ,ios,iphone开发基础:使用GDataXML解析XML文档,(libxml/tree.h not found 错误解决方案)

    使用GDataXML解析XML文档 在IOS平台上进行XML文档的解析有很多种方法,在SDK里面有自带的解析方法,但是大多情况下都倾向于用第三方的库,原因是解析效率更高.使用上更方便 这里主要介绍一下 ...

  5. Objective-C ,ios,iphone开发基础:picker控件详解与使用,(实现省市的二级联动)

    第一步:新建一个单视图(single view)的工程, 命名为pickerTest,不要勾选下面两个选项,第一个是新版本里面的,第二个是单元测试,现在用不着. 点击next  ->creat之 ...

  6. Objective-C ,ios,iphone开发基础:几个常用类-NSNumber

    2013-08-21 在Objective-C,包括int double float 等等再内的基础数据类型都不是一个类,所以就不能给它们发送消息,也就是说不能调用方法,那怎么办呢 ?Objectiv ...

  7. Objective-C ,ios,iphone开发基础:JSON解析(使用苹果官方提供的JSON库:NSJSONSerialization)

    json和xml的普及个人觉得是为了简化阅读难度,以及减轻网络负荷,json和xml 数据格式在格式化以后都是一种树状结构,可以树藤摸瓜的得到你想要的任何果子. 而不格式化的时候json和xml 又是 ...

  8. Objective-C ,ios,iphone开发基础:http网络编程

    - (IBAction)loadData:(id)sender { NSURL* url = [NSURL URLWithString:@"http://162.105.65.251:808 ...

  9. Objective-C ,ios,iphone开发基础:3分钟教你做一个iphone手机浏览器

    第一步:新建一个Single View工程: 第二步:新建好工程,关闭arc. 第三步:拖放一个Text Field 一个UIButton 和一个 UIWebView . Text Field 的ti ...

随机推荐

  1. 软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试] [附加题]

    软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试] [附加题] 首先,在分组之前,我和室友薛亚杰已经详细阅读了往届学长的博客,认为电梯调度 ...

  2. POJ 1511 Invitation Cards (最短路spfa)

    Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...

  3. Spring MVC MultiActionController example

    In Spring MVC application, MultiActionController is used to group related actions into a single cont ...

  4. codeforces 630J Divisibility

    J. Divisibility time limit per test 0.5 seconds memory limit per test 64 megabytes input standard in ...

  5. JQuery学习使用笔记 -- JQuery插件开发

    内容转载自 http://www.css88.com/archives/4821 扩展jQuery插件和方法的作用是非常强大的,它可以节省大量开发时间.这篇文章将概述jQuery插件开发的基本知识,最 ...

  6. Unity3D之Mecanim动画系统学习笔记(二):模型导入

    我们要在Unity3D中使用上模型和动画,需要经过下面几个阶段的制作,下面以一个人形的模型开发为准来介绍. 模型制作 模型建模(Modelling) 我们的美术在建模时一般会制作一个称为T-Pose( ...

  7. C语言单向循环链表解决约瑟夫问题

    据说著名犹太历史学家 Josephus有过以下的故事:在罗马人占领乔塔帕特后,39 个犹太人与Josephus及他的朋友躲到一个洞中,39个犹太人决定宁愿死也不要被敌人抓到,于是决定了一个自杀方式,4 ...

  8. do{...}while(0)的作用

    不是为了循环的while. 1.用于宏定义,保证宏一定按照想要的方式执行. #define   foo(x)     start(x); end(x) if(flag) foo(x); 扩展以后的结果 ...

  9. C#文件后缀名详解

    C#文件后缀名详解 .sln:解决方案文件,为解决方案资源管理器提供显示管理文件的图形接口所需的信息. .csproj:项目文件,创建应用程序所需的引用.数据连接.文件夹和文件的信息. .aspx:W ...

  10. HtmlAgilityPack相关网页

    //多线程 http://www.cnblogs.com/jiangming/archive/2012/09/11/MultiThreadCallWebbrowser.html //替换Webbrow ...