zoukankan      html  css  js  c++  java
  • ios 学习札记 细节(三)

    本节纪录学习WebView的心得

    1.包含web的controller遵从UIWebViewDelegate协议。

    2.定义 UIWebView 与 URL

    @property (nonatomic, strong) UIWebView *mainWebView;

    @property (nonatomic, strong) NSURL *URL;

    3.发送Web页面请求

    - (void)loadView

    {

        mainWebView = [[UIWebViewalloc] initWithFrame:[UIScreenmainScreen].bounds];

        mainWebView.delegate = self;

        mainWebView.scalesPageToFit = YES;

        [mainWebViewloadRequest:[NSURLRequestrequestWithURL:self.URL]];

        self.view = mainWebView;

    }

    4.实现代理部分

    #pragma mark -

    #pragma mark UIWebViewDelegate

    - (void)webViewDidStartLoad:(UIWebView *)webView

    {

        //打开菊花

        [[UIApplicationsharedApplication] setNetworkActivityIndicatorVisible:YES];

    }

    - (void)webViewDidFinishLoad:(UIWebView *)webView

    {

        //关闭菊花

       [[UIApplicationsharedApplication] setNetworkActivityIndicatorVisible:NO];    

        self.navigationItem.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];

    }

    - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error

    {

        [[UIApplicationsharedApplication] setNetworkActivityIndicatorVisible:NO];

    }

    5.加载本地html页面

    假设工程目录下有1.html ,222.js,test1.css,iWebView是一成员变量:

    UIWebView *iWebView;

    //加载本地使用说明文件文件

    -(void)loadDocument:(NSString *)docName 

    {

        NSString *mainBundleDirectory=[[NSBundle mainBundle] bundlePath];

        NSString *path=[mainBundleDirectory stringByAppendingPathComponent:docName];

        

        NSURL *url=[NSURL fileURLWithPath:path];

        NSURLRequest *request=[NSURLRequestrequestWithURL:url];

        iWebView.scalesPageToFit=YES;

        [iWebViewloadRequest:request];

    }

     使用的时候,直接调用:

    [self loadDocument];

     

    7.联网时候的菊花加载还可以参照以下:

    http://www.cnblogs.com/zhuqil/archive/2011/07/28/2119923.html

     

  • 相关阅读:
    iOS8之后,UITableViewRowAction实现滑动多个按钮
    关于UINavigationController的一些技巧
    NSRegularExpression 使用
    UIWindow
    SVN:The working copy is locked due to a previous error (二)
    iOS监听电话来电、挂断、拨号等
    UIDeviceOrientation 和 UIInterfaceOrientation
    java_day03
    java_day 02
    java_day_02
  • 原文地址:https://www.cnblogs.com/Peterahan/p/2644486.html
Copyright © 2011-2022 走看看