我正在为基于消息的iPhone应用程序工作。在我的应用程序中,我已经在UITextView中加载了消息内容,并在UITextView上添加了一个UIImage。
现在,我想通过持有 UITextView并向用户显示复制选项来选择所有UITextView内容。目前用户hold UITextView some of the content only selecting
时。
任何人请帮我这样做?提前谢谢。
修改
在UITableView CellForRowAtIndexPath
委托
customMessageTextView = [[MessageTextView alloc] initWithFrame:CGRectZero];
customMessageTextView.tag = 100;
UIFont *font = [UIFont fontWithName:@"Helvetica" size:15];
customMessageTextView.font = font;
customMessageTextView.scrollEnabled = NO;
customMessageTextView.delegate = self;
customMessageTextView.dataDetectorTypes = UIDataDetectorTypeLink;
[cell.contentView addSubview:customMessageTextView];
[customMessageTextView sizeToFit];
for (UIGestureRecognizer *recognizer in customMessageTextView.gestureRecognizers)
{
if ([recognizer isKindOfClass:[UILongPressGestureRecognizer class]])
{
recognizer.enabled = NO;
}
}
UILongPressGestureRecognizer *myLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(selectAllTextFromCustomMessageTextView)];
[customMessageTextView addGestureRecognizer:myLongPressRecognizer];
[myLongPressRecognizer release];
UILongPressGestureRecognizer操作:
-(void) selectAllTextFromCustomMessageTextView
{
NSLog(@"Select All Text Messages");
customMessageTextView.selectedRange = NSMakeRange(0, customMessageTextView.text.length);
}
答案 0 :(得分:2)
如果我理解正确,您希望在按住UITextView
(即放大镜等)时禁用标准行为。也许你甚至禁用了编辑选项。如果是这样,您只需向UILongPressGestureRecognizer
添加UITextView
。您可能必须默认禁用内置于UILongPressGestureRecognizer
的{{1}}。您可以找到一种方法here。
然后在UITextView
操作方法中,您只需选择视图中的所有文字:
UILongPressGestureRecognizer
请注意,这会显示复制/剪切/粘贴菜单。但是,如果您的文字视图确实禁用了用户编辑,则菜单只会包含复制。