iOS笔记之_UITetxView文本选择复制

UITetxView文本选择复制

PasteboardTextView.m

#import "PasteboardTextView.h"

@implementation PasteboardTextView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.font = [UIFont systemFontOfSize:15.f];
        self.editable = NO;
        self.textColor = [UIColor grayColor];
        self.text = @"这里是UITextView中需要选中复制的文字";
        self.textAlignment = NSTextAlignmentCenter;
        self.backgroundColor = [UIColor yellowColor];
    }
    return self;
}

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender

{
    //屏蔽了除复制以外的功能
    if (action == @selector(copy:)) {
        return YES;
    }else{
        
        return NO;
    }
    
}

@end
ViewController.m

#import "PasteboardTextView.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    PasteboardTextView *textv = [[PasteboardTextView alloc] initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width,50)];
    
    [self.view addSubview:textv];
}
@end
就酱...
iOS笔记之_UITetxView文本选择复制_第1张图片
Paste_Image.png

你可能感兴趣的:(iOS笔记之_UITetxView文本选择复制)