美文网首页
webView上添加自定view

webView上添加自定view

作者: 蜗牛锅 | 来源:发表于2017-05-28 11:51 被阅读13次
   // 创建一个webView
    UIWebView * webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    // 加载网页
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com"]]];
    // 这里是关键了
    webView.scrollView.contentInset= UIEdgeInsetsMake(200,0,0,0);
    // 把webView添加到视图上
    [self.view addSubview:webView];
    
    // 这里也是关键
    UIView* head = [[UIView alloc] initWithFrame:CGRectMake(0, -200,self.view.frame.size.width,200)];
    
    // 给自定义view设个背景色
    head.backgroundColor= [UIColor orangeColor];
    
    // 把自定义的view添加到webView的scrollView上面!!!
    [webView.scrollView addSubview:head];
    
  //  添加完自定义的view以后,网页加载出来之前,下面会有黑色的方框,下面是去掉的方法
    //去掉黑色框框
    webView.scrollView.contentOffset= CGPointMake(0, -100);
    // -100是自己瞎写的,根据不同情况设定,黑框越大,这个数就越小!是负数的小!!

相关文章

网友评论

      本文标题:webView上添加自定view

      本文链接:https://www.haomeiwen.com/subject/kethfxtx.html