background image

点击该视图后打开一个网址。

    创建视图类的.h 文件

[cpp] 

#import   
  
@interface MyView : UIView  
  
@end  

    创建视图类的.m 文件

    显示的图片资源为通过 URL 下载后谷歌的 LOGO,点击该 LOGO 视图后程序将打开百
度的主页。

[cpp] 

#import "MyView.h"  
  
@implementation MyView  
  
- (id)initWithFrameCGRect)frame  
{  
    //初始化视图位置  
    self = [super initWithFrame:frame];  
    if (self) {  
         
    }  
    return self;  
}  
  
  
- (void)drawRectCGRect)rect  
{  
    //这里创建一个图片视图  
       UIImage  *image=[[UIImage  alloc]initWithData:[NSData  dataWithContentsOfURL:[NSURL 
URLWithString"http://www.google.com.hk/intl/zh-CN/images/logo_cn.png"]]];  
    [image drawInRect:CGRectMake(0, 0,self.frame.size.width , self.frame.size.height)];  
    [image release];  
}  
    
-(void)touchesEndedNSSet *)touches withEventUIEvent *)event