I want to crop part of my UIWebView so I can take away part of the website. I want to take off some room from the top of a website. Here is my code so you can tell me what I have to do to crop it. I've just started to code so explaining a little what your doing will help heaps!:
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)
}
UIWebView
has a scrollView
property. We can adjust the insets of the the scrollView
like so:
let topSpace = -100 //or however large
webView.scrollView.contentInset = UIEdgeInsets(top: topSpace, left: 0, bottom: 0, right: 0)
webView.scrollView.bounces = false
The final line is so the user can't scroll up and see the cut off piece.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.