网页显示UIWebView(一个)
1.scalesPageToFit設置為YES,這樣web頁面會依據(jù)屏幕大小進行自己主動縮放。
2.UIWebView的狀態(tài)監(jiān)視
//內(nèi)容讀入開始前被調(diào)用。將UIWebView,返回no后UIWebView不進行讀入處理。假設想在單擊鏈接時進行獨自處理則處理
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
//內(nèi)容讀入開始后被調(diào)用
- (void)webViewDidStartLoad:(UIWebView *)webView;
//內(nèi)容讀入結束后被調(diào)用
- (void)webViewDidFinishLoad:(UIWebView *)webView;
//內(nèi)容讀入過程中發(fā)生錯誤后被調(diào)用??啥啻握{(diào)用
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
webViewController.h中的代碼。?
@interface webViewController : UIViewController<UIWebViewDelegate> {UIActivityIndicatorView *activityIndicatorView; } @property(nonatomic,strong) UIWebView * webView; @end webViewController.m中的代碼。 - (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.self.title = @"明白顯示通信狀態(tài)";//UIWebView的設置_webView =[[UIWebView alloc]init];_webView.delegate = self;_webView.frame = self.view.bounds;_webView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;_webView.scalesPageToFit = YES;[self.view addSubview:_webView];//工具條中加入活動指示器activityIndicatorView = [[UIActivityIndicatorView alloc]init];activityIndicatorView.frame = CGRectMake(0, 0, 20, 20);UIBarButtonItem *indicator = [[UIBarButtonItem alloc]initWithCustomView:activityIndicatorView];UIBarButtonItem *adjustment = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];NSArray *buttons = [NSArray arrayWithObjects:adjustment,indicator,adjustment, nil];[self setToolbarItems:buttons animated:YES];}-(void)viewDidAppear:(BOOL)animated {[super viewDidAppear:animated];//顯示web頁面NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];[_webView loadRequest:request]; }-(void)webViewDidStartLoad:(UIWebView *)webView {[activityIndicatorView startAnimating]; } -(void)webViewDidFinishLoad:(UIWebView *)webView {[activityIndicatorView stopAnimating];} -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {[activityIndicatorView stopAnimating];UIAlertView * alerView = [[UIAlertView alloc]initWithTitle:@"網(wǎng)絡問題" message:@"請檢查網(wǎng)絡" delegate:self cancelButtonTitle:@"刪除" otherButtonTitles:@"確定", nil];[self.view addSubview:alerView];[alerView show];}版權聲明:本文博客原創(chuàng)文章。博客,未經(jīng)同意,不得轉載。
總結
以上是生活随笔為你收集整理的网页显示UIWebView(一个)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL installer
- 下一篇: struts2 标签的使用之二 s:it