I am currently displaying text in a uiwebview. However, I would like to allow a user to select text and perform some action with the selected text (google it). Apple has done th
Starting in iOS 3.2 you can use UIMenuController to add additional UIMenuItems to the system menu that appears when selecting text in a UIWebView. Here's a simple example:
- (void)viewDidLoad {
[super viewDidLoad];
UIMenuItem *defineItem = [[[UIMenuItem alloc] initWithTitle:@"Define" action:@selector(defineSelection:)] autorelease];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObject:defineItem]];
}
- (void)defineSelection:(id)sender {
NSString *selection = [webView stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
// Do something with the selection
}
Apple describes how this works in the Adding Custom Edit Menu Items section of the Device Features Programming Guide.
This recent blog post from a developer would seem to suggest that at least in the iPad iOS branch, some iBooks functionality is based on private APIs.