gpt4 book ai didi

objective-c - UIWebView 中的自定义菜单控件

转载 作者:行者123 更新时间:2023-12-02 06:40:12 26 4
gpt4 key购买 nike

我想通过使用在 UIWebView 中创建自定义菜单控件

- (void) setUpCustomMenu 
{

Class cls1 = NSClassFromString(@"UIMenuController");
Class cls2 = NSClassFromString(@"UIMenuItem");

if (cls1 && cls2)

if ([UIMenuController instancesRespondToSelector:@selector(setMenuItems:)])
{
UIMenuItem* item1 = [[UIMenuItem alloc] initWithTitle:@"My Menu Item" action:@selector(myMenuAction:)];
[UIMenuController sharedMenuController].menuItems = [NSArray arrayWithObjects:item1, nil];;
[item1 release];
}

}

但我无法创建自定义菜单,请指导我。

最佳答案

扩展系统编辑菜单

NSMutableArray *extraItems = [[NSMutableArray alloc] init];
UIMenuItem *boldItem = [[UIMenuItem alloc] initWithTitle:@”Bold”
action:@selector(bold:)];
[extraItems addObject:boldItem];
[[UIMenuController sharedMenuController].menuItems = extraItems;

UIWebView扩展系统编辑菜单

// For your UIWebView subclass:
- (void)bold:(id)sender {
[self stringByEvaluatingJavaScript:@”document.execCommand(‘Bold’)];
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(bold:))
return YES;
return [super canPerformAction:action
withSender:sender];
}

关于objective-c - UIWebView 中的自定义菜单控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9394072/

26 4 0