這次需求有復(fù)制功能,把字符串復(fù)制到系統(tǒng)剪貼板,
1.在 View 里貼上scrollView
2.在scrollView里貼上 UITextView,用于上下滑動展示完整數(shù)據(jù)
// 邀請鏈接
UIView *linkView2 = [[UIView alloc] init];
linkView2.backgroundColor = [UIColor whiteColor];
linkView2.frame = CGRectMake(0, CGRectGetMaxY(line.frame), UI_View_Width, cellH);
[self.view addSubview:linkView2];
// 邀請鏈接label
UILabel *linkLabel2 = [[UILabel alloc] init];
linkLabel2.backgroundColor = [UIColor clearColor];
linkLabel2.frame = CGRectMake(marginX, -1, 60, cellH);
linkLabel2.text = @"邀請鏈接";
linkLabel2.font = setupTextLabelFont;
linkLabel2.textColor = XHHColor(102, 102, 102);
[linkView2 addSubview:linkLabel2];
// 復(fù)制按鈕
UIButton *copyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[copyBtn setTitle:@"復(fù)制" forState:UIControlStateNormal];
copyBtn.frame = CGRectMake(UI_View_Width - marginX - btnW, (cellH - btnH) * 0.5, btnW, btnH);
copyBtn.titleLabel.font = [UIFont systemFontOfSize:12];
[copyBtn addTarget:self action :@selector(copylinkBtnClick) forControlEvents:UIControlEventTouchUpInside];
copyBtn.backgroundColor = [UIColor whiteColor];
[copyBtn setTitleColor:XHHTitleColor forState:UIControlStateNormal];
copyBtn.layer.borderColor = XHHTitleColor.CGColor;
copyBtn.layer.cornerRadius = XHH_btnCornerRadius;
copyBtn.layer.borderWidth = 1.0f;
[linkView2 addSubview:copyBtn];
self.copylinkBtn = copyBtn;
// 滑動邀請鏈接
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(linkLabel2.frame), 0, UI_View_Width - linkLabel2.width - btnW - marginX * 2, cellH)];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.bounces = NO;
[linkView2 addSubview:scrollView];
UITextView *link = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, UI_View_Width - linkLabel2.width - btnW - marginX * 2, 50)];
link.text = @"wwww.ujfwegertkyluiopafsdfghnlrjkliop[sdfghjklertyui";
link.textColor = [UIColor grayColor];
link.textContainer.maximumNumberOfLines = 1;
link.scrollEnabled = YES;//是否可以拖動
link.editable = NO;//禁止編輯
[scrollView addSubview:link];
scrollView.contentSize = CGSizeMake(CGRectGetWidth(link.bounds), 50);
self.link = link;
/**
* 復(fù)制鏈接
*/
- (void)copylinkBtnClick {
[MBProgressHUD showSuccess:@"復(fù)制成功!"];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = self.link.text;
}