我正在爲基於消息的iPhone應用程序工作。在我的應用程序中,我在UITextView中加載了消息內容,並在UITextView上添加了UIImage。如何通過暫停選擇所有UITextview內容並通過編程方式顯示覆制選項iphone?
現在我想通過舉辦的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);
}
感謝您的回答。我正在嘗試你的指示。我會讓你知道結果。再次感謝。 – Gopinath
它不適合我。我會發布我的代碼。你可以幫我嗎?謝謝。 – Gopinath
你是對的,設置'selectedRange'屬性不起作用。我用一種應該可以工作的方法更新了我的答案(這次我已經測試過了)。 – pajevic