UIWebView背景透明且无拖拽后的上下阴影

来源:互联网 发布:zsysecdesk是什么软件 编辑:程序博客网 时间:2024/05/22 00:42

1.首先UIWebView背景透明

    // set background transparent, also can set it in nib file    webView_.backgroundColor = [UIColor clearColor];    webView_.opaque = NO;

2.隐藏拖拽webview时上下的两个有阴影效果的subview

    // remove shadow view when drag web view    for (UIView *subView in [webView_ subviews]) {        if ([subView isKindOfClass:[UIScrollView class]]) {            for (UIView *shadowView in [subView subviews]) {                if ([shadowView isKindOfClass:[UIImageView class]]) {                    shadowView.hidden = YES;                }            }        }    }

其他
a.UIWebView加载本地html

    // get html file path    NSString *path = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"];    [webView_ loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];

b.禁用UIWebView拖拽时的反弹效果

    // disable view bounce    [(UIScrollView *)[[webView_ subviews] objectAtIndex:0] setBounces:NO];

c.禁用UIWebView拖拽

    // disable touch move    <script type="text/javascript">        document.ontouchmove = function(e) {            e.preventDefault();        }    </script>
获取UIWebview加载的标题和内容代码:
titleLabel.text = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];

NSString *source = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];

 

获取网页的全部原数据:

NSString *html = [webView stringByEvaluatingJavaScriptFromString:

@"document.documentElement.outerHTML"];

 

读取某一div的内容:

    NSString *html = [myWebViewstringByEvaluatingJavaScriptFromString: 

@"document.getElementById('your div id').textContent"];

 

UIWebview缓存页面

[webView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: url] 

                                           cachePolicy: NSURLRequestUseProtocolCachePolicy 

                                       timeoutInterval: 3600.0]]; 

原创粉丝点击