【代码笔记】iOS-可拷贝的label

时间:2022-12-02 00:40:15

一,效果图。

【代码笔记】iOS-可拷贝的label

二,工程图。

【代码笔记】iOS-可拷贝的label

三,代码。

ViewController.m

【代码笔记】iOS-可拷贝的label
#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
【代码笔记】iOS-可拷贝的label