【代碼筆記】iOS-可拷貝的label,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