Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone:Pop up button in UIWebView

I want to put pop up button like Email in UIWebView.In my app i have created ebook

in webView now whenever i click(long press) on index page link it will create the pop up

window with open and copy button as shwon as below: enter image description here

Like this i want to put another button like Email and Print.How to create another button in pop up window in WebView?Thanks in advance!

like image 324
Developer Avatar asked Dec 26 '11 05:12

Developer


People also ask

What is UIWebView on Iphone?

What is UIWebView? UIWebView is a deprecated iOS user interface control in Apple's UIKit framework. It loads HTML files and web content into an app view, rendering them as they would appear in a browser window.

What does UI web view mean?

Android is powered by Chrome. Mobile Safari UIWebView. The UIWebView is different from the ordinary Safari browser, as it is not a stand-alone browser, but merely browser functionality that is embedded in a third party app that allows the app to display content from the web.


1 Answers

The popup you refer to is called a UIMenuController. You can access the [UIMenuController sharedMenuController] method to get the menu controller. You can then add your own UIMenuItems to the menu controller.

UIMenuItem* myBtn1 = [[[UIMenuItem alloc] initWithTitle: @"Button 1" action:@selector( onButton1: )] autorelease];
UIMenuItem* myBtn2 = [[[UIMenuItem alloc] initWithTitle: @"Button 2" action:@selector( onButton2: )] autorelease];
UIMenuController* mc = [UIMenuController sharedMenuController];
mc.menuItems = [NSArray arrayWithObjects: myBtn1, myBtn2, nil];

Now implement the methods

- (void) onButton1: (UIMenuController*) sender
{
}

- (void) onButton2: (UIMenuController*) sender
{
}

For more detail refer apple's Doc.

Edit

you can implement Long Gesture

UILongPressGestureRecognizer* gr = [[[UILongPressGestureRecognizer alloc] initWithTarget: self action: @selector( onShowMenu: ) ] autorelease];
   [_myview addGestureRecognizer: gr];



- (void) onShowMenu: (UIGestureRecognizer*) sender
{
    [sender.view becomeFirstResponder];

    UIMenuController* mc = [UIMenuController sharedMenuController];

    CGRect bounds = sender.view.bounds;

    [mc setTargetRect: sender.view.frame inView: sender.view.superview];
    [mc setMenuVisible: YES animated: YES];
}
like image 129
Maulik Avatar answered Oct 15 '22 17:10

Maulik