Add UIButton in a UIWebView

前端 未结 4 1277
花落未央
花落未央 2021-01-14 18:41

I have a UIWebView which is already filled by my request (loadRequest).

I would like to add a UIButton in it. It\'s easy to write this simple code :

         


        
4条回答
  •  萌比男神i
    2021-01-14 19:08

    You can inject html markup such as into the content of your UIWebview using stringByEvaluatingJavaScriptFromString method.

    To capture the click event and prevent it from reloading content of your webview use this delegate:

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
    {
        if(navigationType==UIWebViewNavigationTypeLinkClicked && [[request.URL absoluteString] isEqualToString: @"yourTag01"])
        {
            //your custom action code goes here
            return NO;
        }
        return YES;
    }
    

提交回复
热议问题