iOS开发之复制字符串到剪贴板
概述
详细

一、主要思路
1.在 View 里贴上scrollView
2.在scrollView里贴上 UITextView,用于上下滑动展示完整数据
二、程序实现
1、在 View 里贴上scrollView
- (void)setupUI {
CGFloat marginX = 15;
CGFloat cellH = 50;
CGFloat btnW = 70;
CGFloat btnH = 30;
// 邀请链接
UIView *linkView2 = [[UIView alloc] init];
linkView2.backgroundColor = [UIColor whiteColor];
linkView2.frame = CGRectMake(0, 100, 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 = [UIFont systemFontOfSize:14];
linkLabel2.textColor = ZLColor(102, 102, 102);
[linkView2 addSubview:linkLabel2];
// 复制按钮
UIButton *copyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[copyBtn setTitle:@"复制" 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:ZLColor(108, 187, 82) forState:UIControlStateNormal];
copyBtn.layer.borderColor = ZLColor(108, 187, 82).CGColor;
copyBtn.layer.cornerRadius = 3.0;
copyBtn.layer.borderWidth = 1.0f;
[linkView2 addSubview:copyBtn];
// 滑动邀请链接
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(linkLabel2.frame), 0, UI_View_Width - 60 - 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 - 60 - 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;
}
2、在scrollView里贴上 UITextView,用于上下滑动展示完整数据
#pragma mark - 按钮点击事件操作 /**
* 复制链接
*/
- (void)copylinkBtnClick { NSLog(@"复制内容: %@", self.link.text); UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = self.link.text;
}
三、压缩文件截图及运行效果
1、压缩文件截图

2、当显示过多则滚动显示的运行时的截图

四、其他补充
界面性问题可以根据自己项目需求调整即可, 具体可参考代码, 项目能够直接运行!
注:本文著作权归作者,由demo大师发表,拒绝转载,转载需要作者授权
iOS开发之复制字符串到剪贴板的更多相关文章
- ios-复制字符串到剪贴板
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = self.label.text;
- android 复制字符串到剪贴板
public static void CopyToClipboard(Context context,String text){ ClipboardManager clip = (ClipboardM ...
- iOS开发之--复制粘贴功能
复制粘贴功能,代码如下: 1.复制功能 UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = ...
- iOS开发 Date转字符串
+ (NSString *)formatterDate:(NSNumber *)desDate WithDateFormatter:(NSString *)formatter{ NSDateForma ...
- IOS 开发中判断字符串是否为空字符的方法
NSUInteger是无符号的整型, NSInteger是有符号的整型,在表视图应用中常见 NSUInteger row= [indexPath row];因为这是显示tableViewCell有多少 ...
- ios开发之--复制到剪切板
仅做记录: UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = @"你好&quo ...
- IOS开发基础知识--碎片16
1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...
- IOS开发基础知识碎片-导航
1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...
- iOS开发——总结篇&IOS开发基础知识
IOS开发基础知识 1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断 ...
随机推荐
- struts2点滴记录
1.s:textfield 赋值方法 <s:textfield name="Tname" value="%{#session.Teacher.name}" ...
- 触发器系列(2) DataTrigger
触发条件: DataTrigger是以控件DataContext的属性作为触发条件 本例效果说明: <!--当值为1时将外边框的背景色改为黑色--> <!--当值为2时 改变透明度达 ...
- python 查看模块的存放位置
执行 dlib.__file__ 输出 '/anaconda2/lib/python2.7/site-packages/dlib/__init__.pyc'
- iOS:制作九宫格
制作简单的九宫格: 源码如下: #import "ViewController.h" @interface ViewController () @end @implementati ...
- QT QCharts QScatterSeries 空心点阵图,鼠标移动到上面显示数值,鼠标移开数值消失
在最近接到的需求是这样的,画一个折线图,关键点使用空心的圆点标识出来,鼠标移动到关键点上,显示出当前数值:鼠标移走数值消失. 我们遇到这个需求的时候,第一时间就会想到使用 QLineSeries 画折 ...
- Android ToggleButton Example--开关按钮
Android ToggleButton Example 在 Android 中, “android.widget.ToggleButton” 是个特殊的类,可以渲染出一个“开关按钮” ,顾名思义, ...
- 20 个具有惊艳效果的 jQuery 图像缩放插件
jQuery相对与Flash的魔力已经贯穿整个网络.尽管,Flash层被认为是用于网页设计的首选,然而随着jQuery的出现,以及他的酷似Flash的交互式特效使得网页更加的优雅——Flash开始靠边 ...
- 如何解决SPD的缓存问题
SPD有时候文件被缓存住了,表现为文件的最后更改时间不对,或者本来文件已经被check in了,但是显示check out状态,而此时如果选择check in, 就会提示文件没有被check ou ...
- cocos2d-x -3.81+win7+vs2013开发环境创建新的项目
cocos2d-x -3.81+win7+vs2013开发环境创建新的项目 1.准备阶段 (1) vs2013下载及安装 (2)cocos2d-x 3.8.1下载及解压 (3)python下载及安装( ...
- 4. Add override methods to class
1. In the class, right click 2. "Scource" 3. "Override / Implement Menthods" 4. ...