IOS Clipboard Basics

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.