UI中的网页加载
2015-08-26 08:29
323 查看
- (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.}
相关文章推荐
- IE:获取完整的网页
- IE:脱机浏览网页
- 网页恶意代码的预防
- 对于技术人员的出现了运行时间错误,是否要进行调试的解决方法
- 针对网页制作者的网页打开速度慢的解决方法集合第1/2页
- C#实现将网页保存成图片的网页拍照功能
- IE中用VBScript不提示直接打印的代码
- 网页绿色系配色应用实例图文第1/2页
- 提高CSS网页渲染效率的11点注意事项
- C#下载网页并在控制台输出的方法
- php查看网页源代码的方法
- Winform实现将网页生成图片的方法
- asp.net 抓取网页源码三种实现方法
- js统计网页在线时间的脚本
- C#实现网页截图功能
- 利用AJAX开源项目 在网页里播放视频实现方法
- 使用javascript为网页增加夜间模式
- JS实现网页顶部向下滑出的全国城市切换导航效果
- 基于Bootstrap的网页设计实例