IOS开发之等待页面,结合UIWebView、UIAlertView、UIActivityIndicatorView
1、定义
@property (strong, nonatomic) UIWebView *WebView;
@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator;
@property (strong, nonatomic) UIAlertView *myAlert;
@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator;
@property (strong, nonatomic) UIAlertView *myAlert;
2、UIWebView结合UIActivityIndicatorView实现
//创建UIWebView
_WebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 400)];
[_WebView setUserInteractionEnabled:NO];
[_WebView setBackgroundColor:[UIColor clearColor]];
[_WebView setDelegate:self];
[_WebView setOpaque:NO];//使网页透明
NSString *path = @"http://www.baidu.com";
NSURL *url = [NSURL URLWithString:path];
[_WebView loadRequest:[NSURLRequest requestWithURL:url]];
//创建UIActivityIndicatorView背底半透明View
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[view setTag:103];
[view setBackgroundColor:[UIColor blackColor]];
[view setAlpha:0.8];
[self.view addSubview:view];
_activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
[_activityIndicator setCenter:view.center];
[_activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[view addSubview:_activityIndicator];
[self.view addSubview:_WebView];
_WebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 400)];
[_WebView setUserInteractionEnabled:NO];
[_WebView setBackgroundColor:[UIColor clearColor]];
[_WebView setDelegate:self];
[_WebView setOpaque:NO];//使网页透明
NSString *path = @"http://www.baidu.com";
NSURL *url = [NSURL URLWithString:path];
[_WebView loadRequest:[NSURLRequest requestWithURL:url]];
//创建UIActivityIndicatorView背底半透明View
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[view setTag:103];
[view setBackgroundColor:[UIColor blackColor]];
[view setAlpha:0.8];
[self.view addSubview:view];
_activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
[_activityIndicator setCenter:view.center];
[_activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[view addSubview:_activityIndicator];
[self.view addSubview:_WebView];
-(void)webViewDidStartLoad:(UIWebView *)webView
{
[_activityIndicator startAnimating];
}
{
[_activityIndicator startAnimating];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
[_activityIndicator stopAnimating];
UIView *view = (UIView *)[self.view viewWithTag:103];
[view removeFromSuperview];
}
{
[_activityIndicator stopAnimating];
UIView *view = (UIView *)[self.view viewWithTag:103];
[view removeFromSuperview];
}
3、UIAlertView结合UIActivityIndicatorView实现
-(void)webViewDidStartLoad:(UIWebView *)webView
{
//[_activityIndicator startAnimating];
if (_myAlert==nil){
_myAlert = [[UIAlertView alloc] initWithTitle:nil
message: @"读取中..."
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];
_activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
_activityIndicator.frame = CGRectMake(120.f, 48.0f, 38.0f, 38.0f);
[_myAlert addSubview:_activityIndicator];
[_activityIndicator startAnimating];
[_myAlert show];
}
}
{
//[_activityIndicator startAnimating];
if (_myAlert==nil){
_myAlert = [[UIAlertView alloc] initWithTitle:nil
message: @"读取中..."
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];
_activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
_activityIndicator.frame = CGRectMake(120.f, 48.0f, 38.0f, 38.0f);
[_myAlert addSubview:_activityIndicator];
[_activityIndicator startAnimating];
[_myAlert show];
}
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
[_myAlert dismissWithClickedButtonIndex:0 animated:YES];
}
{
[_myAlert dismissWithClickedButtonIndex:0 animated:YES];
}
浙公网安备 33010602011771号