Post

New PasteButton in iOS 16

iOS 16 introduced a new SwiftUI button called PasteButton.

Previously, when trying to paste content from another application, users were prompted for permission on every single paste operation unless a per-app system setting is manually changed by the user. This could quickly become cumbersome and disrupt the flow of tasks. However, iOS 16 addresses this issue by introducing PasteButton.

PasteButton allows to paste content of a specified type from the clipboard without the need to ask the user for permission. This is because, unlike other apps, developers cannot tamper with the pasteboard contents.

The button only active when the system’s Pasteboard (UIPasteboard) has an actual payload of the requested content type available for pasting. This helps users easily identify when the PasteButton can be utilized.

While the PasteButton proves to be a useful addition to SwiftUI, it does have some limitations in terms of visual customization. Developers can modify the button’s appearance using .buttonBorderShape(...)labelStyle(_:), and tint(_:). Unfortunately, there doesn’t seem to be an option to display just the paste icon symbol without a border.

1
2
3
4
5
6
7
8
9
PasteButton(payloadType: String.self) { strings in
    guard let string = strings.first else {
        return
    }
    text = string
}
.buttonBorderShape(.capsule)
.labelStyle(.iconOnly)
.tint(.red)

Examples of customized PasteButton

This post is licensed under CC BY 4.0 by the author.