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) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断 ...
随机推荐
- ASP.NET Core 1.0基础之依赖注入
来源https://docs.asp.net/en/latest/fundamentals/dependency-injection.html ASP.NET Core 1.0在设计上原生就支持和 ...
- Selenium2+python自动化36-判断元素存在
前言 最近有很多小伙伴在问如何判断一个元素是否存在,这个方法在selenium里面是没有的,需要自己写咯. 元素不存在的话,操作元素会报错,或者元素有多个,不唯一的时候也会报错.本篇介绍两种判断元素存 ...
- mybatis 模糊查询和<![CDATA[ ]]>的作用
1. sql中字符串拼接 SELECT * FROM tableName WHERE name LIKE CONCAT(CONCAT('%', #{text}), '%'); 2. 使用 ${...} ...
- JAVA压缩解压ZIP文件,中文乱码还需要ANT.JAR包
package zip; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStrea ...
- strstr实现
// strstr.c查找完全匹配的子字符串 #include<stdio.h> #include<string.h> char *my_strstr(const char * ...
- Installing Apache Spark on Ubuntu 16.04
Santosh Srinivas on 07 Nov 2016, tagged onApache Spark, Analytics, Data Minin I've finally got to a ...
- scala的一些特殊用法
1.创建多行字符串,只要把多行字符串放在3个双引号间("""...""")即可.这是Scala对于here document,或者叫here ...
- [6] 胶囊体(Capsule)图形的生成算法
顶点数据的生成 bool YfBuildCapsuleVertices ( Yreal radius, Yreal height, Yuint slices, Yuint stacks, YeOrig ...
- 第十四章 Executors源码解析
前边两章介绍了基础线程池ThreadPoolExecutor的使用方式.工作机理.参数详细介绍以及核心源码解析. 具体的介绍请参照: 第十二章 ThreadPoolExecutor使用与工作机理 第十 ...
- [leetcode]Sort List @ Python
原题地址:http://oj.leetcode.com/problems/sort-list/ 题意:链表的排序.要求:时间复杂度O(nlogn),空间复杂度O(1). 解题思路:由于题目对时间复杂度 ...