UIWebView

可看

码:

//网页视图

    self.webView = [[UIWebView allocinitWithFrame:CGRectMake(00kScreenWidthkScreenHeight - kNavigationBarHeight)];

    //网络地址

    NSURL *url = [NSURL URLWithString:@"http://my.csdn.net/my/mycsdn"];

//    网络请求

//    NSURLRequest *request = [NSURLRequest requestWithURL:url];

1.//    [self.webView loadRequest:request];

    

    //自适应设备的屏幕

    self.webView.scalesPageToFit = YES;

    [self.view addSubview:self.webView];

   

2.

    //加载HTML

    NSString *htmlPath = [[NSBundle mainBundlepathForResource:@"news" ofType:@"html"];

    NSString *htmlStr = [[NSString allocinitWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];

    

    //拼接字符串

    NSString *fullStr = [NSString stringWithFormat:htmlStr, title, content, time, source];

    

    /*

    //字符串举例

    NSString *s = @"%@%@%@%@%@";

    NSString *ss = [NSString stringWithFormat:s,@"1",@"1",@"1",@"1",@"1"];

    */

    

    [self.webView loadHTMLString:fullStr baseURL:nil];



//监控

  _activityView = [[UIActivityIndicatorView allocinitWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    UIBarButtonItem *barItem = [[UIBarButtonItem allocinitWithCustomView:_activityView];

    self.navigationItem.rightBarButtonItem = barItem;


self.webView.delegate = self;

#pragma mark - UIWebView Delegate


- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{

    NSLog(@"将要开始加载");

    return YES;

}

- (void)webViewDidStartLoad:(UIWebView *)webView{

    

    NSLog(@"开始加载");

    [_activityView startAnimating];

    

}

- (void)webViewDidFinishLoad:(UIWebView *)webView{

    NSLog(@"加载完成");

    [_activityView stopAnimating];

}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{

    NSLog(@"加载失败,%@",error);

}

你可能感兴趣的:(UIWebView)