The following three controls in iOS have copy-and-paste functionality on their own
1, Uitextview
2, Uitextfield
3, UIWebView
UIKit Framework Several classes and protocols are provided to facilitate our ability to implement the Clipboard in our own applications.
1, Uipasteboard: We can write data to it, can also read the data
2. Uimenucontroller: Displays a shortcut menu to display items for selection, such as copy, clip, paste, and so on.
3. Canperformaction:withsender in Uiresponder: Used to control which commands are displayed in the shortcut menu.
4. Uiresponderstandardeditactions will be called when the command on the shortcut menu is clicked.
The following items can be placed on the Clipboard
1, uipasteboardtypeliststring-string array, including Kuttypeutf8plaintext
2, Uipasteboardtypelisturl-url array, including Kuttypeurl
3. uipasteboardtypelistimage-graphic array, including Kuttypepng and Kuttypejpeg
4, uipasteboardtypelistcolor-color array
The type of clipboard is divided into two types:
System level: Using Uipasteboardnamegeneral and Uipasteboardnamefind, system-level applications shut down, or unloaded data is not lost.
Application-level: By setting, you can have the data remain on the Clipboard after the application is closed, but the data is lost after the application is unloaded. We can use Pasteboardwithname:create: to create.
Examples are as follows:
Sometimes we may need to copy the text on the Uilabel, or the Uiimageview picture, and Uilabel and Uiimageview do not respond to the touch event or copy, then we need to implement a replicable uilabel ourselves. Add a new class to inherit from Uilabel:
In order to receive the event (which can be the first responder), we need to override a method
There are also two methods that need to be covered for replication operations:
With the above three methods, we can handle copy, of course, in case of receiving the event:
We can receive the event because my tap number at the top is set to 2. So you need to double-click to capture, next, we'll deal with Tap, let the menu bar pop out
So a replicable Uilabel is created that handles receiving clicks and processing copy.
IOS Clipboard Basics