UIWebView頁面的控制(二)

來源:互聯網
上載者:User

標籤:frame   dstar   span   UI   按鈕   設定   com   system   運行   

1.UIWebView的內容控制的屬性/方法列表

loading屬性               確認當前頁面是否在讀入中

canGoForward屬性   確認goForward  方法是否可運行,可運行為yes;

canGoBack屬性        確認goBack  方法是否可運行,可運行為yes。

goBack方法               返回前一個頁面

goForword方法          進入下一個頁面

reload方法                 又一次讀入當前頁

stopLoading方法       中止當前頁的讀入

2.webViewController.h

@interface webViewController : UIViewController<UIWebViewDelegate,UINavigationControllerDelegate,UINavigationBarDelegate>{    UIWebView *_webView;}@property(nonatomic,strong)UIBarButtonItem *reloadButton;@property(nonatomic,strong)UIBarButtonItem *stopButton;@property(nonatomic,strong)UIBarButtonItem *backButton;@property(nonatomic,strong)UIBarButtonItem *forwardButton;@end


webViewController.m


- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view.    self.navigationItem.title = @"UIWebView測試版";    _webView = [[UIWebView alloc]init];    _webView.delegate = self;    _webView.frame = self.view.frame;    _webView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;    _webView.scalesPageToFit = YES;    [self.view addSubview:_webView];    //工具條中追加按鈕    _reloadButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(reloadDidPush)];    _stopButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action: @selector(stopDidPush)];    _backButton = [[UIBarButtonItem alloc]initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:@selector(backDidPush)];    _forwardButton = [[UIBarButtonItem alloc]initWithTitle:@"Forward" style:UIBarButtonItemStyleBordered target:self action:@selector(forwardDidPush)];    NSArray *buttons = [NSArray arrayWithObjects:_backButton,_forwardButton,_reloadButton,_stopButton, nil];   [self setToolbarItems:buttons animated:YES];    [self.navigationController setToolbarHidden:NO animated:YES];    }-(void)reloadDidPush{    [_webView reload];//又一次讀入頁面}-(void)stopDidPush{    if(_webView.loading){        [_webView stopLoading];//讀入停止    }    }-(void)backDidPush{    if (_webView.canGoBack) {        [_webView goBack];//返回前一畫面    }}-(void)forwardDidPush{    if (_webView.canGoForward) {        [_webView goForward];//進入下一頁面    }    }-(void)updateControlEnabled{    //統一更新指示按鈕狀態    [UIApplication sharedApplication].networkActivityIndicatorVisible = _webView.loading;    _stopButton.enabled = _webView.loading;    _backButton.enabled = _webView.canGoBack;    _forwardButton.enabled = _webView.canGoForward;    }-(void)viewDidAppear:(BOOL)animated{    //畫面顯示結果後讀入web頁面畫面    [super viewDidAppear:animated];    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];    [_webView loadRequest:request];    [self updateControlEnabled];}-(void)viewWillDisappear:(BOOL)animated{    //畫面關閉時狀態的活動指標設定成off    [super viewWillDisappear:animated];    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;}-(void)webViewDidStartLoad:(UIWebView *)webView{    [self updateControlEnabled];}-(void)webViewDidFinishLoad:(UIWebView *)webView{    [self updateControlEnabled];}-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{    [self updateControlEnabled];}



UIWebView頁面的控制(二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.