iOS之 UIWebView的简单学习

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS之 UIWebView的简单学习相关的知识,希望对你有一定的参考价值。

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的简单学习的主要内容,如果未能解决你的问题,请参考以下文章

ios开发之--UIWebView全属性

代码片段使用复杂的 JavaScript 在 UIWebView 中插入 HTML?

IOS开发-OC学习-常用功能代码片段整理

IOS UIWebView 下拉刷新功能的简单实现

Swift 实践之UIWebView

IOS开发之使用UIWebView实现图文混排