0

我有一个 UItextView 使用我分配了一些手势的代码创建。UItextView 不应该是可编辑的,我还想删除通过按住它来选择文本的可能性,包括显示的菜单剪切/粘贴。我在整个互联网上发现:

- (BOOL)canBecomeFirstResponder {
return NO;
}

我将此代码插入到我的文件中,并设置 text.delegate = self. 我什至在 .h 文件中包含了 UItextViewDelegate 我该怎么办?

4

1 回答 1

1

您应该修改editable.UITextView

要禁用复制粘贴,最简单的方法是继承 UITextView,并canPerformAction:withSender:像这样实现:

@interface MyTextView : UITextView @end

@implementation MyTextView

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    return NO;
}

@end

如果您使用 XIB 或 Storyboard 来布局 UI,请确保为文本视图提供正确的类。

于 2013-02-08T20:23:59.500 回答