// Created by lyz on 15-8-29.
// Copyright (c) 2015年 mac. All rights reserved.
//
#import "BasicViewController.h"
@interface WebViewController : BasicViewController<UIWebViewDelegate>
{
UIWebView *_webview;
UIActivityIndicatorView *_activity;
}
@end
// Created by lyz on 15-8-29.
// Copyright (c) 2015年 mac. All rights reserved.
//
#import "WebViewController.h"
@interface WebViewController ()
@end
@implementation WebViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"文字新闻";
[self _loadweb];
[self _loaddate];
}
- (void)_loadweb{
_webview = [[UIWebView alloc]initWithFrame:self.view.bounds];
//自适应
_webview.scalesPageToFit = YES;
_webview.delegate = self;
[self.view addSubview:_webview];
_activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_activity.frame = CGRectMake(0, 0, 40, 40);
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:_activity];
// NSString *str = @"https://www.baidu.com";
//
// NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:str]];
//
// [webview loadRequest:request];
// NSString *str = [[NSBundle mainBundle]pathForResource:@"test.html" ofType:nil];
//
//
// NSString *htmlstr = [NSString stringWithContentsOfFile:str encoding:NSUTF8StringEncoding error:nil];
//
// [webview loadHTMLString:htmlstr baseURL:nil];
}
- (void)_loaddate{
//1
NSString *str = [[NSBundle mainBundle]pathForResource:@"news.html" ofType:nil];
//2
NSString *htmlstr = [NSString stringWithContentsOfFile:str encoding:NSUTF8StringEncoding error:nil];
//3
NSDictionary *dic = [DateJosn dateWithJosn:@"news_detail.json"];
//4
NSString *title = dic[@"title"];
NSString *content = dic[@"content"];
NSString *time = dic[@"time"];
NSString *source = dic[@"source"];
NSString *author = dic[@"author"];
//5
NSString *html = [NSString stringWithFormat:htmlstr,title,time,author,content,source];
//6
[_webview loadHTMLString:html baseURL:nil];
}
#pragma
- (void)webViewDidStartLoad:(UIWebView *)webView{
[_activity startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
[_activity stopAnimating];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
[_activity stopAnimating];
}