- (void)viewDidLoad
{
[super viewDidLoad];
UIView *bnView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 20)];
backBn = [[UIButton alloc] initWithFrame:CGRectMake(0,0,40,20)];
[backBn setTitle:@"返回" forState:UIControlStateNormal];
//[backBn setBackgroundImage:[UIImage imageNamed:@"backBn.png"] forState:UITouchPhaseBegan];
//[backBn setBackgroundImage:[UIImage imageNamed:@"backBn.png"] forState:UITouchPhaseEnded];
[backBn addTarget:self action:@selector(btn:) forControlEvents:UITouchPhaseEnded];
[bnView setBackgroundColor:[ UIColor brownColor]];
[bnView addSubview:backBn];
[self.view addSubview:bnView];
webView = [[ UIWebView alloc] initWithFrame: CGRectMake(0,20,320,460)];
[webView setUserInteractionEnabled: YES]; //是否支持交互
[webView setDelegate: self ]; //委托
[webView setOpaque: NO ]; //透明
[self.view addSubview : webView]; //加载到自己的view
NSString *page;
NSURL *url;
switch (index) {
case 0:
page= [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"iphone/baobaoweiyang"];
break;
case 1:
page= [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"iphone/richangbaojian"];
break;
case 2:
page= [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"iphone/xinlingjiehuo"];
break;
case 3:
page= [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"iphone/zhunbaba"];
break;
case 4:
page= [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"iphone/zhunmama"];
break;
default:
break;
}
//NSLog(@"%@",page);
url = [[NSURL alloc] initFileURLWithPath:page];
//NSLog(@"%@",url);
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
//webview 加行加载
[webView loadRequest: request];
[request release];
opaqueview = [[ UIView alloc] initWithFrame: CGRectMake(0,0,320,460)];
//opaqueview 需要在.h文件中进行声明用以做UIActivityIndicatorView的容器view;
activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame: CGRectMake(0,0,320,480)];//需要在.h文件中进行声明
[activityIndicator setCenter: opaqueview.center ];
[activityIndicator setActivityIndicatorViewStyle: UIActivityIndicatorViewStyleWhite]; //颜色根据不同的界面自己调整
[opaqueview setBackgroundColor:[ UIColor blackColor]];
[opaqueview setAlpha: 0.6 ];
[self.view addSubview: opaqueview];
[opaqueview addSubview : activityIndicator];
// Do any additional setup after loading the view from its nib.
}
- (void )webViewDidFinishLoad:(UIWebView *)webView {
[activityIndicator stopAnimating];
opaqueview.hidden = YES ;
}
- (void )webViewDidStartLoad:(UIWebView *)webView {
[activityIndicator startAnimating ];
opaqueview.hidden = NO ;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
/*********************************************************************************
函数: - (BOOL)shouldAutorotateToInterfaceOrientation:
功能: 支持屏幕自动转向,此处代码自动生成
参数: (UIInterfaceOrientation)interfaceOrientation
返回值:布尔型的状态值
**********************************************************************************/
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)dealloc
{
[super dealloc];
[webView release];
[backBn release];
[opaqueview release];
[activityIndicator release];
}
@end