Am working for am message based iPhone app. In my application i have loaded the message content in UITextView and added an UIImage on UITextView.
Now i want to select all UITextView content by holding UITextView and show the Copy option to the user. Currently when the user hold UITextView some of the content only selecting.
Any one please help me to do this? Thanks in advance.
EDIT:
In UITableView CellForRowAtIndexPath delegate
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 action:
-(void) selectAllTextFromCustomMessageTextView
{
NSLog(@"Select All Text Messages");
customMessageTextView.selectedRange = NSMakeRange(0, customMessageTextView.text.length);
}
If I understand you correctly you want to disable the standard behaviour when holding in a
UITextView(i.e. the magnifying glass, etc.). Perhaps you have even disabled the editing option. If so you should just add anUILongPressGestureRecognizerto yourUITextView. You might have to disable theUILongPressGestureRecognizerwhich is built intoUITextViewby default. You can find a way to do that here.Then in your
UILongPressGestureRecognizeraction method you simply select all the text in the view:Notice that this will bring up the Copy/Cut/Paste menu. However, if your text view does in fact have user editing disabled the menu will only contain Copy.