2015-06-30 45 views
0

我有麻烦了。我目前正在使用uiwebview来显示内容。但我想显示内容,而不需要在uiwebview中滚动。如何在Swift iOS(Xcode 6.0)中以编程方式更改UIWebView高度

下面的代码。看它

func webViewDidFinishLoad(webView: UIWebView!) { 

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

} 

但它不会改变它的大小。任何人都知道我该怎么办?

在此先感谢。

+0

'webView.frame.size = webView.scrollView.contentSize' – Sujay

+0

但我的webview内滚动视图。 – Viju

+0

我已经为您的“无需在uiwebview中滚动显示内容”回答“ – Sujay

回答

0

试试这个代码

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) 

感谢

1

有一个选项来自动调整你的内容。试试这个:

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

你也可以在storyboard/xib中设置这个属性。请注意,这将启用缩放。

相关问题