简体   繁体   中英

How to change the UIWebView height Programatically in Swift iOS (Xcode 6.0)

i'm in trouble. i'm currently using a uiwebview to display content. but i want to show content without scrolling in uiwebview.

Below the code. look it

func webViewDidFinishLoad(webView: UIWebView!) {

    var newBounds: CGRect = webView.bounds
    newBounds.size.height = webView.scrollView.contentSize.height
    webView.bounds = newBounds

}

but it won't be change its size. Anyone know what should i do ?

Thanks in advance.

There is an option to automatically scale your content. Try this:

// Assumes 'webView' is a property
overload func viewDidLoad() {
    super.viewDidLoad()
    webView.scalesPageToFit = true
}

You can also set this property in the storyboard/xib. Note that this enables zooming.

Try this code

 let webV:UIWebView = UIWebView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height))
 webV.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.jogendra.com")))
 webV.delegate = self;
 self.view.addSubview(webV)

Thanks

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM