我正在尝试在我的应用程序的右上角添加一个按钮,该按钮将重新加载我的 webView
。我试图遵循其他答案 here和 here , 但没有任何运气让按钮出现。
我的 ViewController 类中有以下代码:
override func viewDidLoad() {
super.viewDidLoad()
let webView:UIWebView = UIWebView(frame: CGRectMake(30, 20, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height))
webView.scalesPageToFit = true
webView.multipleTouchEnabled = true
webView.backgroundColor = UIColor.whiteColor()
webView.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.example.com")!))
self.view.addSubview(webView)
}
我想叠加按钮。我如何添加一个按钮以在按下时重新加载 webView
?
最佳答案
您可以简单地将按钮添加到您的 WebView 层次结构中,例如
let buttonFrame = CGRect(x: 50, y: 150, width: 50, height: 50)
let button = UIButton(frame: buttonFrame)
button.backgroundColor = UIColor.greenColor()
webView.scrollView.addSubview(button) // in that way button will be scroling with webView.
或在 webView 上方添加按钮,例如
let buttonFrame = CGRect(x: 50, y: 150, width: 50, height: 50)
let button = UIButton(frame: buttonFrame)
button.backgroundColor = UIColor.greenColor()
insertSubview(button, aboveSubview: webView)
关于ios - 在 UIWebView 上覆盖一个刷新按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38859735/