i want to create the custom menu control in UIWebView, by using
- (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];
}
}
but i am unable to create custom menu, please guide me.
Extend the system-editing menu
NSMutableArray *extraItems = [[NSMutableArray alloc] init];
UIMenuItem *boldItem = [[UIMenuItem alloc] initWithTitle:@”Bold”
action:@selector(bold:)];
[extraItems addObject:boldItem];
[[UIMenuController sharedMenuController].menuItems = extraItems;
UIWebView Extend the system-editing menu
// 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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With