我当前创建了一个 webview,但我不想使用界面生成器来创建后退、前进和刷新按钮。我如何以编程方式创建这些按钮?我知道如何用代码创建常规按钮,但对于 webView 委托(delegate)按钮,我迷失了方向,无法找到很多资源。
最佳答案
来自 UIWebView 文档:
If you allow the user to move back and forward through the webpage history, then you can use the goBack and goForward methods as actions for buttons. Use the canGoBack and canGoForward properties to disable the buttons when the user can’t move in a direction.
然后设置按钮将使用 addTarget:action:forControlEvents:
(如 Sven 所指出的):
[myBackButton addTarget:myWebView
action:@selector(goBack)
forControlEvents:UIControlEventTouchDown];
如果您想根据 canGoBack
和 canGoForward
属性启用/禁用按钮,则必须向 添加一些 KVO 通知UIController
.
关于iphone - 如何以编程方式为 UIWebView 创建后退、前进和刷新按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3639411/