开发者

How to customize UIWebView tap-hold-on-link sheet

开发者 https://www.devze.com 2023-01-14 23:36 出处:网络
I was wondering how I can override the UIActionSheet that appears when tapping and holding your finge开发者_开发知识库r on a link in an UIWebView (it shows the link and an open and copy button). I nee

I was wondering how I can override the UIActionSheet that appears when tapping and holding your finge开发者_开发知识库r on a link in an UIWebView (it shows the link and an open and copy button). I need to add a button to the alert, but I don't know how to customize it.

Does anyone have an idea on how to solve this?


Given that there exists no such API, you still could customize the sheet in a non-standard-api-like-way without using private api. The easiest will probably be to observe the subviews of that webview and when one appears (like a popup) check it's class and if it's such a popup, to customize it. Here's how I'd try that.

Still: this is hacky and might easily break in the next update.

Add observation:

[myWebView addObserver:self forKeyPath:@"subviews" options:0 context:@"popup"];

Then observe:

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context
{
    if (context == @"popup") {
        for (UIView *view in [object subviews]) {
            if ([view isKindOfClass: [UIAlertView class]])
                 [self customizeAlert: (UIAlertView*)view];
        }
    }
    [super observeValueForKeyPath:keyPath
                         ofObject:object
                           change:change
                          context:context];
}

Then do your customization in such a method:

- (void)customizeAlert:(UIAlertView*)alert { ... }
0

精彩评论

暂无评论...
验证码 换一张
取 消