首页 > 移动平台 > 详细

iOS之 UIWebView的简单学习

时间:2016-02-15 11:51:20      阅读:230      评论:0      收藏:0      [点我收藏+]

UIWebView的简单学习

 

 

 

 

#import "ViewController.h"

@interface ViewController ()<UIWebViewDelegate>
{
    UIWebView  *WebView;
    UIView     *view;
    UIActivityIndicatorView *activityIndicator;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    WebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 400)];
    [WebView setUserInteractionEnabled:NO];//是否支持交互
    [WebView setBackgroundColor:[UIColor clearColor]];
    [WebView setDelegate:self];//委托
    [WebView setOpaque:NO];//使网页透明(Opaque为不透明的意思,这里为透明)
    
    //加载网页的方法
    //1.创建并加载远程网页
    NSString *path = @"http://www.baidu.com";
    NSURL *url = [NSURL URLWithString:path];
    [WebView loadRequest:[NSURLRequest requestWithURL:url]];
    
    //创建UIActivityIndicatorView背底半透明View
    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];
    }
    
    //数据加载完
    - (void)webViewDidFinishLoad:(UIWebView *)webView {
        [activityIndicator stopAnimating];
    }

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

iOS之 UIWebView的简单学习

原文:http://www.cnblogs.com/wyhwyh2114/p/5063856.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!