【代码笔记】iOS-可拷贝的label
一,效果图。
二,工程图。
三,代码。
ViewController.m
#import "ViewController.h" #import "MKBeCopyLabel.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. MKBeCopyLabel *copyLabel = [[MKBeCopyLabel alloc]initWithFrame:CGRectMake(10, 100, 100, 60)]; copyLabel.backgroundColor=[UIColor redColor]; copyLabel.text=@"111111"; copyLabel.userInteractionEnabled=YES; UITapGestureRecognizer *tapCopyText = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapToCopyText:)]; [copyLabel addGestureRecognizer:tapCopyText]; [self.view addSubview:copyLabel]; } - (void)handleTapToCopyText:(UITapGestureRecognizer *)sender { MKBeCopyLabel * targetLabel = (MKBeCopyLabel *)sender.view; [targetLabel handleLongTap]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end