Search code examples
iosuiwebviewuibutton

How to add UIButton in front on UIWebView objective C


I want to show a UIButton on a UIWebview. However the UIButton shows behind the webview.

i have tried the below code:

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
    {
        if(navigationType==UIWebViewNavigationTypeLinkClicked && [[request.URL absoluteString] isEqualToString:myURL])
        {

            [_myBtn bringSubviewToFront:self.view];

            [self.myWebView addSubview:_myBtn];

 //i have tried this aswell

            //[_myBtn bringSubviewToFront:self.myWebView];

            //[self.view addSubview:_myBtn];

            return NO;
        }
        return YES;
    }

Any Ideas, what i am doing wrong ? Thanks


Solution

  • Comment out above code and Just move UIButton below the UIWebView in your Storyboard and then check.