0

I've seen people using AttributedString and .link to link to something, but I need it to run a function, not open a browser link. I want something like this in SwiftUI, with wrapping, etc. Terms of service agreement (this image was made with HTML)

I tried buttons, but that results in

HStack {
   Text("By clicking continue you agree to our ")
   Button("Terms Of Service") {}
   Text(" and our ")
   Button("Privacy Policy") {}
}

Awful Looking TOS notification:

enter image description here

koen
  • 5,383
  • 7
  • 50
  • 89

1 Answers1

0

Just use Text

struct ContentView: View {
@State var text: String = ""
@State var textTapped: String = ""
var body: some View {
    VStack {
        HStack(spacing: 0){
            Text("Just text ")
            Text("tap me").onTapGesture {
                tapped()
            }
            Text(" some more text")
        }
        Text(textTapped)
    }
}

func tapped() {
    textTapped = "was tapped"
}

}

enter image description here

Tom
  • 1,319
  • 9
  • 8
  • That still doesn't let them wrap with the text, so you still get my screenshot above when you do that. It's just using the Text() view instead of Button() – Learning SwiftUI Jun 13 '23 at 02:03
  • So, we have a text, it's tappable and runs a method. Looks like I don't understand, what you really want to achieve. – Tom Jun 13 '23 at 07:43