UIWebView是一个能够显示网页的IOS视图控件,我们可以用它来访问一个网站。下面是具体的实例:

操作步骤:

1.首先在xib文件中拖放一个UIWebView控件到view中

2.将下载的页面以及页面资源加载到项目中,但必须选择Create folder references for any added folders,然后知道文件在项目中是蓝色显示,而不是黄色显示

3.将webView的Delegate拖到File's Owner,继承UIWebView的Delegate协议,并且实现他的协议


ViewController.h:

#import <UIKit/UIKit.h>

@interface DXWViewController : UIViewController<UIWebViewDelegate>
@property (retain, nonatomic) IBOutlet UIWebView *webview;
@property(nonatomic,retain) UIAlertView *alert;
@end

ViewController.m:

#import "DXWViewController.h"

@interface DXWViewController ()

@end

@implementation DXWViewController

- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//[self.webview loadRequest:request]; //加载本地资源,html页面
NSString *str = [[NSBundle mainBundle] pathForResource:@"百度图片—全球最大中文图片库" ofType:@"html"]; str = [NSString stringWithContentsOfFile:str encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@",str);
[self.webview loadHTMLString:str baseURL:[[NSBundle mainBundle] bundleURL]];
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (void)dealloc {
[_webview release];
[_alert release];
[super dealloc];
} -(void)webViewDidFinishLoad:(UIWebView *)webView
{
[self.alert dismissWithClickedButtonIndex:0 animated:YES];
} -(void)webViewDidStartLoad:(UIWebView *)webView
{
self.alert = [[UIAlertView alloc] initWithTitle:@"Loading..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[self.alert show]; UIActivityIndicatorView *aiv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
aiv.center = CGPointMake(self.alert.bounds.size.width/2, self.alert.bounds.size.height/2);
[aiv startAnimating];
[self.alert addSubview:aiv];
} @end

[IOS]UIWebView 请求网络页面或者加载本地资源页面的更多相关文章

  1. iOS webView 远程html加载本地资源

    昨天,一个朋友让我帮他在IOS上弄这样一件事情: webView 调用远程URL,并且让远程的web 通过自定义标签能实现内嵌本地的图片.js 或音频等. 比如:在服务器端 的html文件中 这样写到 ...

  2. iOS WebView 加载本地资源(图片,文件等)

    https://www.cnblogs.com/dhui69/p/5596917.html iOS WebView 加载本地资源(图片,文件等) NSString *path = [[NSBundle ...

  3. 填补Resources和WWW加载本地资源的坑

    总的来说Resources和WWW加载本地资源坑比较多,大多与路径有关. 下面代码构成了一个路径的预读模块: 此模块主要解决的坑是:Resources或WWW加载本地的文件夹中的多个文件时,无法获取文 ...

  4. jQuery-Ajax请求Json数据并加载在前端页面,附视频教程讲解!

    Ajax技术应用广泛,这种异步加载技术,无需刷新网页即可更新网站内容,全局或者局部均可,所以大家应该学会这种技巧,把技术用上来. 创建demo.json文件,用来做数据源: {     "t ...

  5. 页面全部加载完毕和页面dom树加载完毕

    dom树加载完毕 $(document).ready()//原生写法document.ready = function (callback) {            ///兼容FF,Google   ...

  6. 引入外部 CDN失效时--怎么加载本地资源文件(本文以jquery为例)

    相信大家都使用过CDN静态资源库,比如下面 CDN官方静态资源库:https://cdnjs.com/ 七牛前端公开库:http://staticfile.org   (vue,react,nl都有) ...

  7. MFC CDHtmlDialog 加载本地资源

    步骤:1.资源视图 项目右击选择资源添加,自定义添加新类型 如:JS(会增加JS文件夹)2. 选择1新建的文件夹右击 添加资源 导入 选择js文件引入3. 在资源文件Resource.h文件夹能找到资 ...

  8. console在ie下不兼容的问题(console在ie9下阻碍页面的加载,打开页面一片空白)

    在页面中加入以下代码: window.console = window.console || (function() { var c = {}; c.log = c.warn = c.debug = ...

  9. vue工程按业务路由打包,页面只加载对应资源

    修改路由表:src/router/index.js import Vue from 'vue'; import Router from 'vue-router'; // 主要写法如下 const Te ...

随机推荐

  1. UVA_埃及分数(Hard Version) UVA 12588

    Problem EEg[y]ptian Fractions (HARD version)Given a fraction a/b, write it as a sum of different Egy ...

  2. Unique Paths 解答

    Question A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram be ...

  3. OpenStack Keystone v3 API新特性

    原连接 http://blog.chinaunix.net/uid-21335514-id-3497996.html keystone的v3 API与v2.0相比有很大的不同,从API的请求格式到re ...

  4. ubuntu查看硬件信息

    1,外部探针probe sudo apt-get install hwinfo 执行hwinfo获取系统信息 --short

  5. 使用ObjectInputStream的readObject()方法如何判断读取到多个对象的结尾

    摘自http://blog.csdn.net/fjdingsd/article/details/46765803 使用ObjectInputStream的readObject()方法如何判断读取到多个 ...

  6. actionInvocation

    1.actionInvocation是什么 ActionInvocation就是Action的调用者.ActionInvocation在Action的执行过程中,负责Interceptor.Actio ...

  7. Beauty of Array(思维)

    Beauty of Array Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward has an array A with N integ ...

  8. 为啥NSString的属性要用copy而不用retain

    之前学习生活中,知道NSString的属性要用copy而不用retain,可是不知道为啥,这两天我研究了一下,然后最终明确了. 详细原因是由于用copy比用retain安全,当是NSString的时候 ...

  9. CSS3实现图片鼠标悬浮放大效果

    .excerpt .focus a img{ -webkit-transition: all ease .3s; transition: all ease .3s }.excerpt .focus a ...

  10. SpringMVC+JPA+Hibernate配置

    首先,Spring配置文件 <?xml version="1.0" encoding="UTF-8"?><beans xmlns=" ...