webView代理


webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 44, 320, 440)];
  [webView setUserInteractionEnabled:YES];//是否支持交互
  //[webView setDelegate:self];
  webView.delegate=self;
  [webView setOpaque:NO];//opaque是不透明的意思
  [webView setScalesPageToFit:YES];//自动缩放以适应屏幕
  [self.view addSubview:webView];
  






#pragma mark - webView高度代理


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

    

    

    NSString *meta = [NSStringstringWithFormat:@"document.getElementsByName(\"viewport\")[0].content = \"width=%f, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\"", webView.frame.size.width];

    [webView stringByEvaluatingJavaScriptFromString:meta];

    

    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '100%'"];

    //字体颜色

    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'gray'"];

    

    //获取页面高度(像素)

    float clientheight = webView.scrollView.contentSize.height;

    //设置到WebView

    webView.frame = CGRectMake(0, 0, iPhoneWidth, clientheight);

    

    // 修改界面的高度

    height_All += clientheight;

    [selfreloadRootContentSize];

    


}


1.隐藏上下滚动时出边界的后面的黑色的阴影
- (void) hideGradientBackground:(UIView*)theView
{
  for (UIView * subview in theView.subviews)
  {
    if ([subview isKindOfClass:[UIImageView class]])
      subview.hidden = YES;

    [self hideGradientBackground:subview];
  }
}

2. 禁用拖拽时的反弹效果
[(UIScrollView *)[[webView subviews] objectAtIndex:0] setBounces:NO];  

3. 判断用户点击类型

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    switch (navigationType) 
    {
        //点击连接
        case UIWebViewNavigationTypeLinkClicked:
        {
            NSLog(@"clicked");
        }
            break;
        //提交表单
        case UIWebViewNavigationTypeFormSubmitted:
        {
            NSLog(@"submitted");
        }
        default:
            break;
    }
    return YES;
}


你可能感兴趣的:(含有代理方法的控件元素)