新建一个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. 【SPOJ】Transposing is even more fun!

    题意: 给出a.b 表示按先行后列的方式储存矩阵 现在要将其转置 可以交换两个点的位置 求最小操作次数 题解: 储存可以将其视为拉成一条链 设a=5.b=2 则在链上坐标用2^***(a,b)表示为( ...

  2. ffmpeg 研究

    ffmpeg -codecs | grep mp3 可以查看ffmpeg是否把mp3编解码模块编译进去了. libmp3lame is the mp3 encoder for ffmpeg. It n ...

  3. usb mass storage device

    Problem adding USB host device to KVM Windows guest machine. Status: CLOSED CURRENTRELEASE   Aliases ...

  4. 第二百四十四、五天 how can I 坚持

    昨天忘了.不知咋忘的,加班加迷糊了? 昨天联调接口,又加班了,好歹基本调通了. 今天,下午,开会,有点被领导批的意思,不是批我,是批我们团队. 团队. 不懂自己. 这样做有意义嘛. 睡觉.好烦. 到底 ...

  5. Nginx和Tengine解决高并发和高可用,而非推荐Apache

    什么是Nginx  什么是Tengine 看看国内大公司在用Nginx和Tengine吗? 步骤一:进入 https://www.taobao.com/,按F12.可看到 有很多APP对淘宝进行请求. ...

  6. UVALive 7461 Separating Pebbles (计算几何)

    Separating Pebbles 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/H Description http://7 ...

  7. UVALive 7325 Book Borders (模拟)

    Book Borders 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/B Description A book is bein ...

  8. POJ1228(稳定凸包问题)

    题目:Grandpa's Estate   题意:输入一个凸包上的点(没有凸包内部的点,要么是凸包顶点,要么是凸包边上的点),判断这个凸包是否稳定.所谓稳 定就是判断能不能在原有凸包上加点,得到一个更 ...

  9. 解决iPhone上select时常失去焦点,随意跳到下一个输入框,影响用户操作

    window.addEventListener('load', function() { FastClick.attach(document.body); }, false); //300s延迟,解决 ...

  10. ASMB的BUG(ORA-04030 kfmditer)导致数据库宕机

    ASMB的BUG(ORA-04030 kfmditer)导致数据库宕机 现象: 客户的一个重要生产系统RAC的一个实例宕机,查看alert日志: Fri Jun 21 17:05:52 2013 Er ...