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 ...
随机推荐
- AHOI2013 Round2 Day2 简要题解
第一题: 第一问可以用划分树或主席树在O(nlog2n)内做出来. 第二问可以用树状数组套主席树在O(nlog2n)内做出来. 我的代码太挫了,空间刚刚卡过...(在bzoj上) 第二题: 分治,将询 ...
- 记录一次Android交叉编译ffmpeg排查错误
Android版本手机直播引擎中,引用了libvlc开源库.项目接过来,发现编译脚本中使用了很多用户名下的绝对路径.项目相关人离职,导致这个脚本实际上已经废掉.而且不知道相关路径下有没有其他文件和第三 ...
- 第二百四十七天 how can I 坚持
今天去了趟北海公园,看到地铁宣传图片挺好看的,实景也倒是不错,环境好了,哪都好,今天是蓝天白云啊. 回来的路上看了,扎克伯格对质疑的回应.哎.改变世界在硅谷是行动,而不是口号.change the w ...
- [ASP.NET MVC] Child actions are not allowed to perform redirect
我在Umbraco平台下,用MVC(SurfaceController)开发时,遇到这个问题 MemberEdit是一个partial View [HttpGet] [ActionName(" ...
- Qt 自动搜索串口号列表
@功能: SerialPortList 类实现当前可用的串口进行实时扫描,当发现有新的串口 或是现有串口消失时,SerialPortList类将发出一个QStringList类型的 信号onNewSe ...
- 深入学习APC
一.前言 在NT中,有两种类型的APCs:用户模式和内核模式.用户APCs运行在用户模式下目标线程当前上下文中,并且需要从目标线程得到许可来运行.特别是,用户模式的APCs需要目标线程处在alerta ...
- SQLServer2008设置开启INTERNET远程连接
SQL Server 2008默认是不允许远程连接的,sa帐户默认禁用的,如果想要在本地用SSMS连接远程服务器上的SQL Server 2008,需要做两个部分的配置: 使用sa账户登录SQL Se ...
- IEBrowse学习笔记
//登录 private void toolStripButton1_Click(object sender, EventArgs e) { //ie.ExecuteScript("aler ...
- SqlServer刷新所有视图
CREATE PROCEDURE RefreshAllView AS DECLARE MyCursor CURSOR FOR select Name from dbo.sysobjects where ...
- VMM服务模板(虚机、APP)部署排错
I won't focus this blog on how to create a service template but more on how you can track the change ...