您好,登錄后才能下訂單哦!
UIWebView是一個能夠顯示網頁的IOS視圖控件,我們可以用它來訪問一個網站。下面是具體的實例:
操作步驟:
#import <UIKit/UIKit.h> @interface DXWViewController : UIViewController<UIWebViewDelegate> @property (retain, nonatomic) IBOutlet UIWebView *webview; @property(nonatomic,retain) UIAlertView *alert; @end
#import "DXWViewController.h" @interface DXWViewController () @end @implementation DXWViewController - (void)viewDidLoad { [super viewDidLoad]; NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; //[self.webview loadRequest:request]; //加載本地資源,html頁面 NSString *str = [[NSBundle mainBundle] pathForResource:@"百度圖片—全球最大中文圖片庫" ofType:@"html"]; str = [NSString stringWithContentsOfFile:str encoding:NSUTF8StringEncoding error:nil]; NSLog(@"%@",str); [self.webview loadHTMLString:str baseURL:[[NSBundle mainBundle] bundleURL]]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { [_webview release]; [_alert release]; [super dealloc]; } -(void)webViewDidFinishLoad:(UIWebView *)webView { [self.alert dismissWithClickedButtonIndex:0 animated:YES]; } -(void)webViewDidStartLoad:(UIWebView *)webView { self.alert = [[UIAlertView alloc] initWithTitle:@"Loading..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; [self.alert show]; UIActivityIndicatorView *aiv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; aiv.center = CGPointMake(self.alert.bounds.size.width/2, self.alert.bounds.size.height/2); [aiv startAnimating]; [self.alert addSubview:aiv]; } @end
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。