UIPasteboard 剪切板

前言

  • Objective-C

    1
    NS_CLASS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED __WATCHOS_PROHIBITED @interface UIPasteboard : NSObject

1、UIPasteboard 简介

  • 顾名思义,UIPasteboard 是剪切板功能,因为 iOS 的原生控件 UITextField、UITextView、UIWebView,我们在使用时如果长按,就会出现复制、剪切、选中、全选、粘贴等功能,这个就是利用了系统剪切板功能来实现的,而每一个 App 都可以去访问系统剪切板。

2、pasteboard 的创建

  • Objective-C

    1
    2
    3
    4
    5
    6
    7
    8
    // 获取系统剪切板
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];

    // 将 label 的文字存储到剪切板
    pasteboard.string = self.label.text;

    // 将剪切板的文字赋值给 label
    self.label.text = pasteboard.string;
文章目录
  1. 1. 前言
  2. 2. 1、UIPasteboard 简介
  3. 3. 2、pasteboard 的创建
隐藏目录