Search code examples
buttonswiftuims-wordmarkdownparagraph

SwiftUI, How to set a word as a button in the paragraph?


I would like to make "here" a button on this note. Anyone could you tell me how to do that?

enter image description here


Solution

  • A possible approach is to use mark-down text with link and handle link by intercepting url.

    Tested with Xcode 13.4 / iOS 15.5

    enter image description here

    Here is main part:

            Text("All your information are confidential. For more information please refer to [here](conf_info)")
        }
        .environment(\.openURL, OpenURLAction { url in
            if url == URL(string: "conf_info") { // << intercept key
                showDetails()
                return .handled
            }
            return .systemAction
        })
    

    Test module on GitHub