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元素的时候,包含autocorrectautocapitalize属性,来指定键盘的行为,如下:

显示电话号码、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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Git使用
下一篇:如何使用Github?

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2023年09月02日 23时09分40秒