Contents

UIPasteControl

A button that a person taps to place pasteboard contents in your app.

Declaration

@MainActor class UIPasteControl

Overview

You can configure the button to appear as an icon, text, or both. The following button represents the icon and text option:

[Image]

In iOS 16 and later, programmatic pasting raises a user alert that prompts the user for approval before the app gains access to pasteboard contents (UIPasteboard.general.string). Use this class to paste without a user prompt.

Add a paste button to a text view

The following code displays a paste button and assigns a text view as the recipient of pasteboard contents:

let textView = UITextView(frame: view.bounds)
view.addSubview(textView)

let configuration = UIPasteControl.Configuration()
configuration.baseBackgroundColor = .red
configuration.baseForegroundColor = .magenta
configuration.cornerStyle = .capsule
configuration.displayMode = .iconAndLabel
                    
let pasteButton = UIPasteControl(configuration: configuration)
pasteButton.frame = CGRect(x: view.bounds.width/2.0, y: view.bounds.height/2.0, width: 150, height: 60)
textView.addSubview(pasteButton)

pasteButton.target = textView

Topics

Creating a paste button

Identifying the content recipient

Determining the button’s look

See Also

Pasteboard