本文简单介绍下在IOS中,webView的基本用法,也顺便强化下自己的基础知识----天明少羽爬楼梯
一、加载外部HTML

报错:NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802) 或者 App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
改错:其中在iOS 9 新建的项目中这种加载 要注意plist的配置 App Transport Security Settings 中添加Allow Arbitrary Loads 改 NO 为 YES。
二、加载本地HTML

一些属性的设置:
webView.scalespageToFit = YES; // 对页面进行缩放以适应屏幕
webView.detectsPhoneNumbers = YES; //检测网页上的电话号码,单击可以拨打
//为UIWebview添加背景图片
webView.backgroundColor=[UIColor clearColor];
webView.opaque=NO;//这句话很重要,webView是否是不透明的,no为透明 在webView下添加个imageView展示图片就可以了

一些代理方法:

其中:-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*) reuqest navigationType: (UIWebViewNavigationType)navigationType;//当网页视图被指示载入内容而得到通知。应当返回YES,这样会进行加载。通过导航类型参数可以得到请求发起的原因,可以是以下任意值:
UIWebViewNavigationTypeLinkClicked
UIWebViewNavigationTypeFormSubmitted
UIWebViewNavigationTypeBackForward
UIWebViewNavigationTypeReload
UIWebViewNavigationTypeFormResubmitted
UIWebViewNavigationTypeOther
scrollview的代理方法:

UIWebView的小知识点最下面的知识点

2.加载txt文件中文显示乱码问题

网友评论