UIWebView

作者: 古月思吉 | 来源:发表于2017-09-19 21:30 被阅读0次

1.功能:
UIWebView是一个用来展示url链接资源的UI控件

2.如何创建:

UIWebView * webView = [[UIWebView alloc]initWithFrame:CGRectMake(0,0, 320, 480)];//创建一个webView
[self.window addSubview:webView];//加到屏幕上

3.如何加载本地数据:

//先去找到这张要支持gif图片的地址,将这个地址转换成url对象
//[NSBundle mainBundle] 用来获取当前程序在运行时的沙盒路径
//NSLog(@"Bundle:%@",[NSBundle mainBundle]);//打印沙盒路径
NSURL * url = [[NSBundle mainBundle]URLForResource:@"舔" withExtension:@"gif"];
NSData * imageData = [[NSData alloc]initWithContentsOfURL:url];//通过url对象,将这个地址的图片转换成二进制的对象
[webView loadData:imageData MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];//下面让webView去加载这个url

4.如何加载网络请求:

NSURL * netUrl = [NSURL URLWithString:@"http://www.baidu.com"];//创建一个网址对象
NSURLRequest * request = [NSURLRequest requestWithURL:netUrl];//将网址转换成请求对象
[webView loadRequest:request];//加载请求

相关文章

网友评论

      本文标题:UIWebView

      本文链接:https://www.haomeiwen.com/subject/etxtsxtx.html