Implementation of SwiftUI clicking on any text to switch between read-only and editable at will

insert image description here



Functional Requirements

When we build an interface with SwiftUI, for simplicity, we often want the text to switch between read-only and editable modes after the user clicks on the view, so that we don't need to build an additional editing interface.

insert image description here

As shown above, when the user clicks the row corresponding to the color in the list, the original read-only text immediately becomes editable; when the user finishes editing and clicks the input button, the view becomes read-only again.

This is a very useful trick in SwiftUI, wondering how to implement it?

In fact, it's incredibly simple!

Let’s Go!


PS: There are two other blog posts with similar content, please click the link below to watch:

Guess you like

Origin blog.csdn.net/mydo/article/details/123119367