iPhone应用开发之四:UIImageView和UIWebView的详细讲解

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 17:44 点击:

 

Andy-清风原创,转载请注明,谢谢。

1.UIImageView的讲解

(1)初始化

 

UIImageView  *imageView =[[UIImageView alloc] initWithFrame:CGRectMake(0.0,45.0,300,300)]; 

 

imageView.image = [UIImage imageNamed:@"a.png"];//加载入图片 

 

[self.view addSubView:image]; 

 

 

也可以这样声明:

 

UIImage *image =[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURLURLWithString:@"/uploads/allimg/201202/20120215101107189.jpg"]]]; 

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];  

 

在加载入图片的时候有两种加载UIImage的方法:如下:

-》1

 

[UIImage imageNamed:@"a.png"]; 

 

-》2

 

NSString *path = [[NSBundle mainBundle] pathForResource:@”icon” 

ofType:@”png”]; 

myImage = [UIImage imageWithContentsOfFile:path]; 

 

如果找到图片,装载到iPhone系统缓存图象。那意味图片是(理论上)放在内存里作为cache的。因此如果图片资源多了或大了,此方式容易引起发生内存警告从而导致自动退出的问题。

最好是通过直接读取文件路径[UIImage imageWithContentsOfFile]解决掉这个问题.

 

NSImage *image = [[NSImage alloc]initWithContentsOfURL:(NSURL *)]; 

NSImage *image = [[NSImage alloc]initWithContentsOfFile:(NSString *)]; 

 

 

最后要记得释放掉image。

 

 

(2)利用UIImageView实现幻灯片效果

 

利用UIImageView和UISider来制作幻灯片。

 

ImagesViewController.h 

 

#import<UIKit/UIKit.h> 

 

  

 

@interfaceImagesViewController : UIViewController 

 

 

         UIImageView *imageView; 

 

         UISlider *slider; 

 

 

  

 

@property (nonatomic,retain) IBOutlet UIImageView *imageView; 

 

@property (nonatomic,retain) IBOutlet UISlider *slider; 

 

  

 

-(IBAction)sliderAction:(id)sender; 

 

  

 

@end 

 

  

 

ImagesViewController.m 

 

 

 

#import"ImagesViewController.h" 

 

#import"Constants.h" 

 

 

 

#define kMinDuration 0.0 

 

#define kMaxDuration 10.0 

 

  

 

@implementationImagesViewController 

 

  

 

@synthesize imageView,slider; 

 

  

 

- (void)dealloc 

 

 

         [imageView release]; 

 

         [slider release]; 

 

         

 

         [super dealloc]; 

 

 

  

 

- (void)viewDidLoad 

 

{        

 

         [super v

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • Lexical or Preprocessor Issue 'xxx.h
    • ios学习笔记(二)xcode 4.3.2下实现基本交互
    • ios版本的helloworld
    • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
    • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
    • IOS类似iphone通讯录TableView的完整demo【附源码】
    • UITableView一些方法
    • [iPhone中级]iPhone团购信息客户端的开发 (二)
    • 如何为Iphone应用创建启动界面
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1