温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

UI中的网页加载

发布时间:2020-08-06 07:30:23 来源:网络 阅读:329 作者:ladispartion1 栏目:开发技术

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.title = @"图片新闻";

    //新建网页视图

    webView = [[UIWebView alloc]initWithFrame:self.view.bounds];

    //网页视图自适应屏幕尺寸

    webView.scalesPageToFit = YES;

    //设置代理

    webView.delegate = self;

    [self.view addSubview:webView];

    

    //加载百度

//    //创建request对象

//    NSMutableURLRequest *mResquest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];

//    //网页控件加载一个

//    [webView loadRequest:mResquest];

    

    //初始化风火轮

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

}

//结束加载

- (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.

}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI