Use Text(.init(["KEY"]("Click here")) and access "KEY" with .environment(.\openURL, _) to make just that text clickable. iOS 15 is required.
enum NavigationKey {
static let welcome = "CLICK_HERE_KEY"
}
struct ContentView: View {
let actionKey = "[Click here](\(NavigationKey.welcome))"
var body: some View {
VStack {
Text("`Hello, World!` phrase that is written in a multiline text with some extra description. The description is not clickable, just a button. ") +
Text(.init(actionKey))
.underline()
}
.tint(.pink)
.padding()
.environment(\.openURL, OpenURLAction { url in
if url.description == NavigationKey.welcome {
print("`Click here` pressed")
}
return .discarded
})
}
}