How to make UITextView text available to everyone and show copy option for iPhone application for iPhone?

I work in an iPhone application, for example in an iMessage application. I designed a page similar to iMessage with the addition of bubbles. As I did, I just added UITextView in UITableView Cell and also i have added UIImageView on UITextView with bubble images .

Load text into a UITextView from NSMutableArray. It is working fine. Now I doubt:

  • The iMessage application is set to when the user hold the bubble they making the text as selectable and showing Copy option . In my application when the user hold a bubble the Copy option showing but some particular text only copying . How can I select all the text and show the user copy option?

  • In iMessage, the selection area (two lines at the beginning of the selection and the end of the selection) is not displayed. But in my application, selection regions are showing how can i manage that?

Could you help me solve these problems? Thanks in advance.

+4
source share
2 answers

Finally, I solved my problem using below code. Now I can select all the contents from a UITextView and show the copy option to the user to copy the message. Please find the code for reference.

 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if (action == @selector(copy:)) { [self selectAll:self]; return YES; } else if (action == @selector(cut:)) { return NO; } return NO; } - (void)copy:(id)sender { UIPasteboard *pastBoard = [UIPasteboard generalPasteboard]; [pastBoard setString:self.text]; self.selectedTextRange = nil; } 

Happy coding.

+7
source

Here, How you can select text in a UITextView

 [textView setSelectedRange:NSMakeRange(row, length)]; 

where row indicates which line you want to start your selection from. length - the total length of the text.

 eg [textView setSelectedRange:NSMakeRange(1, 45)]; // where 1 is first row, and 45 is length of text of selection. 
+1
source

Source: https://habr.com/ru/post/1433971/


All Articles