2012-03-28 62 views

回答

1

UIMenuController单是黑色弹出与按钮和文档具有良好的信息如何处理(手动显示,添加新项目,响应操作等)。

至于获取选定的文本,我看到您在UIWebView中使用可编辑div,这意味着您必须通过JavaScript响应编辑操作。

+0

太好了。谢谢! – Slinky 2012-03-28 20:57:49

2

本教程回答您详细的问题:)

http://ios-blog.co.uk/category/tutorials/rich-text-editing-a-simple-start-part-1/

具体而言,添加菜单项,这样做从部分3.将根视图控制器的实现文件下面的以下内容:

UIMenuItem *highlightMenuItem = [[UIMenuItem alloc] initWithTitle:@"Highlight" action:@selector(highlight)]; 
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObject:highlightMenuItem]]; 

与高亮方法如下:

- (void)highlight { 
    NSString *currentColor = [webView stringByEvaluatingJavaScriptFromString:@"document.queryCommandValue('backColor')"]; 
    if ([currentColor isEqualToString:@"rgb(255, 255, 0)"]) { 
     [webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('backColor', false, 'white')"]; 
    } else { 
     [webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('backColor', false, 'yellow')"]; 
    } 
} 
+0

虽然该教程有一些很好的信息,但它也充满了一些非常脏的肮脏黑客和不好的做法。你应该把大部分你在里面读到的东西用大量的盐。 – 2012-03-28 23:44:41