iPhone:UIWebView中的弹出按钮 [英] iphone:Pop up button in UIWebView
问题描述
我想在UIWebView中放置诸如电子邮件之类的弹出按钮.在我的应用中,我已经创建了电子书
I want to put pop up button like Email in UIWebView.In my app i have created ebook
现在在webView中,只要我单击(长按)索引页面链接,它就会创建弹出窗口
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:
像这样,我想放置另一个按钮,例如电子邮件"和打印".如何在WebView的弹出窗口中创建另一个按钮?谢谢!
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!
推荐答案
您引用的弹出窗口称为 UIMenuController
.您可以访问 [UIMenuController sharedMenuController]
方法以获取菜单控制器.然后,您可以将自己的 UIMenuItems
添加到菜单控制器.
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];
现在实现方法
- (void) onButton1: (UIMenuController*) sender
{
}
- (void) onButton2: (UIMenuController*) sender
{
}
有关更多详细信息,请参见苹果的文档.
For more detail refer apple's Doc.
修改
您可以实施长手势"
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];
}
这篇关于iPhone:UIWebView中的弹出按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!