LoginSignup
1
1

More than 5 years have passed since last update.

Remove AlertView Title in UIWebView

Last updated at Posted at 2017-05-05

Background

The app uses webview to load web-page in iPad. When javascript call the function alert, iPad will call a message, e.g.
IMG_0187.PNG
As you can see, the title of alert view is the domain name of this page, but it's ugly or should be in secrecy. So the task is to hide or remove the title of the alert view.

Solution

We can add category to UIWebView to catch up the alert and show another new alert with no title.

@interface UIWebView (JavaScriptAlert)

- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame;

@end

@implementation UIWebView (JavaScriptAlert)

- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {


    UIAlertView* customAlert = [[UIAlertView alloc] initWithTitle:@""
                                                          message:message
                                                         delegate:nil
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];

    [customAlert show];
    [customAlert release];

}

@end

Now we will get a new alert view with no title, but notice that the message will be in bold font.
IMG_0188.PNG

Reference

Apple API Reference
Relevant problem on stackoverflow
Another solution on stackoverflow

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1