开发者

To make the text in a text view so that it cant be copied

HI All,

I need to display some text in text view, but i want no one should be able to copy/change it while re开发者_StackOverflow社区ading that text. I have already set _TextView.editable=FALSE where _TextView is the object of the text field, but still it gives the option to the user to copy the text.

Also at the end of the text I want to give a URL and want it to display it in blue & underlined and if user click on this text part then it will connect him to the mentioned web page.

How can I do this.

Please help me.

Many Thanks in advance!!


Create a subclass of UITextView and override canPerformAction:withSender:

@interface MyTextView : UITextView {

}

@implementation MyTextView

-(BOOL) canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(copy:))
        return NO;
    if (action == @selector(cut:))
        return NO;
    return [super canPerformAction:action withSender:sender];
}

@end

To enable clickable links set textView.dataDetectorTypes to UIDataDetectorTypeLink.


For the first part if you set User Interaction Enabled to off then they won't have the option to copy the text.

This will however make any "detected" URL un-clickable.

I think it might end up being a choice of either or in this case.

Hope this helps, M.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜