Re: iOS: selectable but not editable text

Bob Stern

On 12 Apr 2022, at 2:24, Gerriet M. Denkmann wrote:

How can I make my Text selectable?

I don’t know a perfect solution for allowing a user to select and copy static text in SwiftUI.

If you use a TextField instead of Text, the content will be selectable, but it also will be editable, which you do not want. A workaround would be to implement the onEditingChanged() and/or onCommit() closures to revert the content to the original text.

Alternatives that seem less Mac-like might be to use a Button instead of a Text view, or a Text view with an onTapGesture() modifier as I believe Jens suggested.

Bob Stern

Join { to automatically receive all group messages.