
UIWebView
发布日期:2022-03-18 08:27:36
浏览次数:25
分类:技术文章
本文共 2184 字,大约阅读时间需要 7 分钟。
UIWebView
显示网页内容
本内容来自
加载本地内容
使用loadData:MIMEType:textEncodingName:baseURL:
或者loadHTMLString:baseURL:
方法,来加载本地内容。
loadData:MIMEType:textEncodingName:baseURL:
来,在web中加载pdf: - (void)viewDidLoad { [super viewDidLoad]; NSString *thePath = [[NSBundle mainBundle] pathForResource:@"iPhone_User_Guide" ofType:@"pdf"]; if (thePath) { NSData *pdfData = [NSData dataWithContentsOfFile:thePath]; [(UIWebView *)self.view loadData:pdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil]; }}
加载网络内容
[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]]];
使用代理来管理,网络的加载:
- (void)webViewDidStartLoad:(UIWebView *)webView{ // starting the load, show the activity indicator in the status bar [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;}- (void)webViewDidFinishLoad:(UIWebView *)webView{ // finished loading, hide the activity indicator in the status bar [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;}- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ // load error, hide the activity indicator in the status bar [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; // report the error inside the webview NSString* errorString = [NSString stringWithFormat: @"An error occurred:%@ ", error.localizedDescription]; [self.myWebView loadHTMLString:errorString baseURL:nil];}
在webView消失的时候停止加载,一般在view controller的viewWillDisappear:
方法中:
- (void)viewWillDisappear:(BOOL)animated{ if ( [self.myWebView loading] ) { [self.myWebView stopLoading]; } self.myWebView.delegate = nil; // disconnect the delegate as the webview is hidden [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;}
管理键盘
例如,可以在定义input元素的时候,包含autocorrect
和autocapitalize
属性,来指定键盘的行为,如下:
显示电话号码、email、URL键盘,type使用 tel, email,或者 url关键字。显示数字键盘,把pattern的设置为”[0-9]” 或者 “\d*“。
这些关键字和pattern属性是HTML5的一部分,iOS是支持的。下面的列表是显示,如何展示每一种键盘,包括标准的键盘:
Text: Telephone: URL: Email: Zip code:
转载地址:https://windzen.blog.csdn.net/article/details/49868355 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2023年09月02日 23时09分40秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
c++性能测试
2019-03-07
c++ strlen 及使用优化
2019-03-07
c++ malloc calloc new [] 及差异
2019-03-07
memset memcpy
2019-03-07
c++ memcpy 快
2019-03-07
c++ strcat
2019-03-07
c++ 冒泡排序、鸡尾酒
2019-03-07
c/c++ 崩溃原因。
2019-03-07
构造函数不写业务逻辑
2019-03-07
window nginx 配置
2019-03-07
dll热更新
2019-03-07
c++ 链表 详解 for应用
2019-03-07
svnadmin 不是内部命令 一招搞定
2019-03-07
error LNK2001: 无法解析的外部符号 “public: virtual
2019-03-07
c++ 自动增长数组 动态数组
2019-03-07
当前不会命中断点,还没有为文档加载任何符号。c++ vs
2019-03-07
程序优化进阶篇(适合各种编程语言)
2019-03-07
GDAL 拼接 镶嵌 投影 shp裁剪
2019-03-07
c++模板类静态成员初始化
2019-03-07