iOS 关于webView的几种应用

创建一个webView :UIWebView*_myWebView=[[UIWebViewalloc]initWithFrame:CGRectMake(0,0,self.view.bounds.size.width,self.view.bounds.size.height-48)];

_myWebView.delegate=self;

[self.viewaddSubview:_myWebView];

1. 加载webView不带有绿字横线,取消打电话的功能。  _myWebView.dataDetectorTypes=UIDataDetectorTypeNone;

2.webView 不弹动    _myWebView.scrollView.bounces=NO;

3.加载一个URL 

NSURL* url = [NSURLURLWithString:@"https://www.baidu.com"];//创建URL

NSURLRequest* request = [NSURLRequestrequestWithURL:url];//创建NSURLRequest

[_myWebViewloadRequest:request];//加载

4.加载一个本地的html

(1).NSString*path = [[NSBundlemainBundle]pathForResource:@"about_12xue_frm"ofType:@"html"];

NSString*htmlString = [NSStringstringWithContentsOfFile:pathencoding:NSUTF8StringEncodingerror:nil];

NSString*basePath = [[NSBundlemainBundle]bundlePath];

NSURL*baseURL = [NSURLfileURLWithPath:basePath];

[_myWebViewloadHTMLString:htmlStringbaseURL:baseURL];   这种是拖入html和图片时选择第一种Create groups。  路径无所谓

(2)Create folder references

这个需要把html放在文件夹里 路径完全需要按照写html的格式,比如拖进去了一个名叫htmlD的文件夹,htmlD里边的关系按相对路径算。

NSURL*url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"about_12xue_frm"ofType:@"html"inDirectory:@"htmlD"]];

NSURLRequest*request = [NSURLRequest requestWithURL:url];

[_myWebViewloadRequest:request];

5.加载一个的字符串

[_myWebViewloadHTMLString:@"123456789"baseURL:nil];

可配上加载后的代理  

#pragma mark - UIWebViewDelegate

- (void)webViewDidFinishLoad:(UIWebView*)webView

{

NSString*meta = [NSStringstringWithFormat:@"document.getElementsByName(\"viewport\")[0].content = \"width=%f, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\"",kDeviceWidth];

[webViewstringByEvaluatingJavaScriptFromString:meta];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • iOS开发系列--网络开发 概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博、微信等,这些应用本身可...
    lichengjin阅读 9,179评论 2 7
  • IOS之UIWebView的使用 刚接触IOS开发1年多,现在对于 混合式 移动端开发越来越流行,因为开发成本上、...
    学无止境666阅读 45,951评论 5 53
  • http://www.cnblogs.com/mddblog/p/5281748.html 一、整体介绍 UIWe...
    F麦子阅读 5,002评论 0 2
  • 一、WebView WebView就是一个内嵌浏览器控件,在iOS中主要有两种WebView:UIWebView和...
    iOS祎阅读 4,806评论 0 2
  • 诗·未言 谁自烟水断桥走来,与谁相遇在杨柳花岸? 谁打开那本合着的书,与谁相忘于梦里江南? 谁念起那首无字的诗,与...
    l一二三四l阅读 3,177评论 0 0