0

I want to implement a onTapGesture on multiple substrings of a string but keeping the whole text view appropiate. For example the String is, "By click on checkbox you agree to our terms of services, privacy policy ..." I want to implement properties such as underline, blue text and onTapGesture, so I can perform Navigation on its active value. How can I achieve that, keeping in my mind, I don't want text jumbled, the whole text should appear as one single text, I tried using concatenation property but, I often get compile errors in Xcode. I tried this approach as well

func combinedTexts: some View {
var texts = strings.map{Text($0)}
            texts[1] = texts[1].foregroundColor(.blue).underline()
            texts[3] = texts[3].foregroundColor(.blue).underline()
            texts[5] = texts[5].foregroundColor(.blue).underline()
            
          
            return texts[1...].reduce(texts[0], +)
}

But was not able to add the onTapGesture as it prompts,

Cannot assign value of some view to subscript of type 'Text'.

What could be the suitable solution for my problem? Thanks ahead!

2
  • 2
    have a look at this SO post/answer to tap on substrings to action some code: stackoverflow.com/questions/70725667/… Commented Nov 21, 2024 at 23:46
  • Thanks @workingdogsupportUkraine for the question link, it did resolve my query. Commented Nov 22, 2024 at 7:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.