欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

UIWebView的用法

发布时间:2023/12/20 编程问答 43 豆豆
生活随笔 收集整理的这篇文章主要介绍了 UIWebView的用法 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

1:首先,介绍一下,如何利用UIWebView来加载HTML编码的字符串。

利用这个技术,也可以轻松地用来显示帮助文档。


First:首先是在您的ViewController中添加下面的代码,这里是我自己兴建的:

// // QFordViewController.h // TestIOS5 // // Created by 七佛 林 on 4/17/12. // Copyright (c) 2012 __MyCompanyName__. All rights reserved. //#import <UIKit/UIKit.h>@interface QFordViewController : UIViewController@property (nonatomic, strong) UIWebView *qfordWebView;@end
Second:然后在实现文件中的代码如下所示:

#import "QFordViewController.h"@interface QFordViewController ()@end@implementation QFordViewController@synthesize qfordWebView; - (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.self.qfordWebView=[[UIWebView alloc] initWithFrame:self.view.bounds];[self.view addSubview:self.qfordWebView];NSString *htmlString = @"Hello,I'm <font color=red><strong>QFord</strong></font>";[self.qfordWebView loadHTMLString:htmlStringbaseURL:nil];}

Third:运行后的效果如下图所示:

2:UIWebView另一个最常用的功能就是用来加载一个页面,也就是URL,可以是本地或者是远程的。

这里我将加载google的官方网页,代码如下:

- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.self.qfordWebView=[[UIWebView alloc] initWithFrame:self.view.bounds];[self.view addSubview:self.qfordWebView];/*NSString *htmlString = @"Hello,I'm <font color=red><strong>QFord</strong></font>";[self.qfordWebView loadHTMLString:htmlStringbaseURL:nil];*/self.qfordWebView.scalesPageToFit = YES;NSURL *url = [NSURL URLWithString:@"http://www.google.com"];NSURLRequest *request = [NSURLRequest requestWithURL:url];[self.qfordWebView loadRequest:request]; }
你可能还会注意到,当你在加载网页时,如果网速比较慢的话,你只能看到界面上白茫茫的一片。那如何提醒用户还在加载网页呢?

这时候你可以借助UIWebViewDelegate,至于如何使用,请您根据这个关键词google一下,请记住,google一直都是你最好的老师,顺便BS下度娘,只能用来找假药。

总结

以上是生活随笔为你收集整理的UIWebView的用法的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。