美文网首页iOS项目
iOS笔记之_UITetxView文本选择复制

iOS笔记之_UITetxView文本选择复制

作者: sunny_轻芒 | 来源:发表于2016-12-07 13:02 被阅读335次

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
就酱...
Paste_Image.png

相关文章

网友评论

    本文标题:iOS笔记之_UITetxView文本选择复制

    本文链接:https://www.haomeiwen.com/subject/zsvdmttx.html