Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom menu control in UIWebView

Tags:

objective-c

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.

like image 355
aarti Garg Avatar asked Aug 28 '26 22:08

aarti Garg


1 Answers

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];
}
like image 93
PeakJi Avatar answered Sep 02 '26 06:09

PeakJi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!