UIWebView的用法
生活随笔
收集整理的這篇文章主要介紹了
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;@endSecond:然后在實現文件中的代碼如下所示: #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的用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html在w3c很多错误,在w3c中验证
- 下一篇: 用什么软件测试光纤稳定性,工欲善其事,谈