How to make UITextView text all selectable and show copy option to the user iPhone app?

做~自己de王妃 提交于 2019-12-05 17:58:32

Finally i have solved my problem used below code. Now am able to select all content from UITextView and showing Copy option to the user to copy the message. Please find the code for your 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.

Here, How you can select text in UITextView

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

where, row indicates from which row you want to start your selection. length is total length of text.

e.g. [textView setSelectedRange:NSMakeRange(1, 45)]; // where 1 is first row, and 45 is length of text of selection.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!