在Xcode 6.4上使用Swift裁剪UIWebView

时间:2015-07-06 07:51:56

标签: ios xcode swift uiwebview xcode6

我想裁剪部分UIWebView,这样我就可以拿走部分网站了。我想从网站顶部取消一些房间。这是我的代码,所以你可以告诉我我要做什么来裁剪它。我刚刚开始编写代码,以便解释一下你的所作所为将有助于堆积!:

    import UIKit
    import WebKit

    class WebView: UIViewController {


@IBOutlet weak var Webview: UIWebView!

var URLPath = "http://www.google.com.au"




override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    loadAdressURL()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

func loadAdressURL(){
    let requestURL = NSURL(string: URLPath)
    let request = NSURLRequest(URL:requestURL!)
    Webview.loadRequest(request)

}

1 个答案:

答案 0 :(得分:0)

UIWebView具有scrollView属性。我们可以调整scrollView的插图,如下所示:

let topSpace = -100    //or however large 
webView.scrollView.contentInset = UIEdgeInsets(top: topSpace, left: 0, bottom: 0, right: 0)
webView.scrollView.bounces = false  

最后一行是这样的,用户无法向上滚动并看到切断的部分。