我正在为基于消息的 iPhone 应用程序工作。在我的应用程序中,我在 UITextView 中加载了消息内容并在 UITextView 上添加了 UIImage。
现在我想通过按住UITextView来选择所有 UITextView 内容并向用户显示 Copy 选项。目前当用户hold UITextView some of the content only selecting
.
任何人请帮我做到这一点?提前致谢。
编辑:
在 UITableViewCellForRowAtIndexPath
委托中
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);
}