UIWebView使用

//  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];



}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值