- (void)_initWebView
{
/**1.创建UIWebView视图*/
_web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, screenW, screenH-64-49)];
_web.delegate = self;
/**2.网页自适应屏幕显示*/
_web.scalesPageToFit = YES;
[self.view addSubview:_web];
}
/**加载数据*/
- (void)loadData
{
/**1.解析JSON*/
NSDictionary *result = [JsonData dataWithFileName:News_detail];
/**2.取出数据*/
NSString *title = result[@"title"];
NSString *content = result[@"content"];
NSString *time = result[@"time"];
NSString *source = result[@"source"];
NSString *author = result[@"author"];
/**3.取得HTML数据*/
NSString *path = [[NSBundle mainBundle] pathForResource:@"news.html" ofType:nil];
NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
/**4.加载HTML数据,需要传入字符串内容*/
/**加载之前拼接字符串*/
NSString *data = [NSString stringWithFormat:html, title ,time, content, author, source];
[_web loadHTMLString:data baseURL:nil];
}
#pragma mark - UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[_act startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[_act stopAnimating];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[_act stopAnimating];
}
27-UIWebView
最新推荐文章于 2021-07-14 12:04:13 发布