zoukankan      html  css  js  c++  java
  • 网页显示UIWebView(一个)

    1.scalesPageToFit设置为YES,这样web页面会依据屏幕大小进行自己主动缩放。

    2.UIWebView的状态监视

    //内容读入開始前被调用。将UIWebView,返回no后UIWebView不进行读入处理。假设想在单击链接时进行独自处理则处理

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

    //内容读入開始后被调用

    - (void)webViewDidStartLoad:(UIWebView *)webView;

    //内容读入结束后被调用

    - (void)webViewDidFinishLoad:(UIWebView *)webView;

    //内容读入过程中发生错误后被调用。可多次调用

    - (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 = @"明白显示通信状态";
        //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:@"网络问题" message:@"请检查网络" delegate:self cancelButtonTitle:@"删除" otherButtonTitles:@"确定", nil];
        [self.view addSubview:alerView];
        [alerView show];
        
    }
    





    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    [NOI2014]起床困难综合症(贪心+位运算)(暑假ACM1 A)
    BZOJ 2456 mode(找众数)(暑假ACM1 F)
    [POI2000]病毒(补全AC自动机)
    [NOI2005]聪聪与可可
    BZOJ4500矩阵
    网络编程物理层
    当列表推导式遇到lambda(匿名函数)
    写学生管理系统后的一些感想
    深入学习python内存管理
    python基础详解
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4750941.html
Copyright © 2011-2022 走看看