读书人

在app里运用webview

发布时间: 2012-09-19 13:43:53 作者: rapoo

在app里使用webview
先建一个view base app. 再打开viewcontroller.xib ,放上一个webview,如果不需要status bar就隐掉,在view里设置。

在viewcontroller.h里加上

IBOutlet UIWebView *webView;


@property (nonatomic, retain) UIWebView *webView;


在ib里,把uiwebview的引用拉上file's owner,选择webView,关联了变量。

viewcontroller.m里加上

@synthesize webView;


加上载入url的代码。
- (void)viewDidLoad {NSString *urlAddress = @"http://www.google.com";//Create a URL object.NSURL *url = [NSURL URLWithString:urlAddress];//URL Requst ObjectNSURLRequest *requestObj = [NSURLRequest requestWithURL:url];//Load the request in the UIWebView.[webView loadRequest:requestObj];}


运行赶来就缺省载入google。如果需要全屏在plist里加上
Status bar is initially hidden = true
如果是横屏就加上
Initial interface orientation=Landscape (right home button)

参考:
http://www.iphonesdkarticles.com/2008/08/uiwebview-tutorial.html
http://www.edumobile.org/iphone/ipad-development/webview-application-in-ipad/#

读书人网 >Web前端

热点推荐