如何在目标c中选择文本时阻止复制按钮出现?

时间:2015-06-16 19:23:04

标签: ios objective-c xcode

我不希望在选择文本时出现“复制/定义”按钮。 我怎么能在目标c中做到这一点?

更新:我想在UIWebView中执行此操作

2 个答案:

答案 0 :(得分:1)

  

禁用粘贴板操作的最简单方法是创建UITextView的子类,该子类覆盖canPerformAction:withSender:方法,为您不想允许的操作返回NO:

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

另见UIResponder

question

发布的rpetrich回答

答案 1 :(得分:0)

以下是发送到`canPerformAction:withSender:

的所有操作
cut:
copy:
select:
selectAll:
paste:
delete:
_promptForReplace:
_transliterateChinese:
_showTextStyleOptions:
_define:
_addShortcut:
_accessibilitySpeak:
_accessibilitySpeakLanguageSelection:
_accessibilityPauseSpeaking:
makeTextWritingDirectionRightToLeft:
makeTextWritingDirectionLeftToRight:

所以你需要删除复制/定义是以下

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(copy:))
        return NO;
    if (action == @selector(_define:))
        return NO;

    return [super canPerformAction:action withSender:sender];
}