0

我有一个自定义的 alertvew,当在 uiwebview 中按下按钮时调用 javascript:

function doSomething(event) { alert("简单测试"); 返回假;我想要那个“警报”打开我的自定义 uialert。可能吗?谢谢

4

1 回答 1

0

发现对我有用的代码:

@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* dialogue = [[UIAlertView alloc] initWithTitle:nil message:message delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];

    UIImage *theImage = [UIImage imageNamed:@"MdC_Base_PopUp.png"];
    theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
    CGSize theSize = [dialogue frame].size;

    UIGraphicsBeginImageContext(theSize);
    [theImage drawInRect:CGRectMake(0, 0, dialogue.frame.size.width, dialogue.frame.size.height)];
    theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    dialogue.layer.contents = (id)[theImage CGImage];

    [dialogue show];
    [dialogue autorelease];
}

@end
于 2012-07-13T08:09:36.050 回答