您好,登錄后才能下訂單哦!
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"圖片新聞";
//新建網(wǎng)頁視圖
webView = [[UIWebView alloc]initWithFrame:self.view.bounds];
//網(wǎng)頁視圖自適應(yīng)屏幕尺寸
webView.scalesPageToFit = YES;
//設(shè)置代理
webView.delegate = self;
[self.view addSubview:webView];
//加載百度
// //創(chuàng)建request對象
// NSMutableURLRequest *mResquest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
// //網(wǎng)頁控件加載一個
// [webView loadRequest:mResquest];
//初始化風(fēng)火輪
UIActivityIndicatorView *ac = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:ac];
self.navigationItem.rightBarButtonItem = rightItem;
[self _loadData];
}
- (void)_loadData{
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"news" ofType:@"html"];
NSError *error = nil;
NSString *str = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
NSDictionary *jsonData = [ReturnJson showJson:news_detail];
NSString *title = [jsonData objectForKey:@"title"];
NSString *source = [jsonData objectForKey:@"source"];
NSString *time = [jsonData objectForKey:@"time"];
NSString *author = [jsonData objectForKey:@"author"];
NSString *content = [jsonData objectForKey:@"content"];
NSString *htmlStr = [NSString stringWithFormat:str,title,source,time,content,author];
[webView loadHTMLString:htmlStr baseURL:nil];
}
#pragma mark-UIWebViewDelegate
//開始加載
- (void)webViewDidStartLoad:(UIWebView *)webView{
UIActivityIndicatorView *ac = (UIActivityIndicatorView *)self.navigationItem.rightBarButtonItem;
[ac startAnimating];
}
//結(jié)束加載
- (void)webViewDidFinishLoad:(UIWebView *)webView{
UIActivityIndicatorView *ac = (UIActivityIndicatorView *)self.navigationItem.rightBarButtonItem;
[ac stopAnimating];
}
//加載出錯
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。