0

I would like to highlight the word that is equal to "searchTerm" within a String. I managed to highlight the whole String with code below. Can someone explain me how to do that? As i know it can be done with attributed string but i have no experience with it.

Text(gesetzestextSKV.marginale)
                        .fontWeight(.bold)
                        .fixedSize(horizontal: false, vertical: true)
                        .padding(.leading)
                        .padding(gesetzestextSKV.marginale.isEmpty ? -20.0 : 0)
                        .background(gesetzestextSKV.marginale.localizedCaseInsensitiveContains(searchTerm) ? Color.yellow : nil)
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
iSoldier
  • 31
  • 1
  • 4
  • Does this answer your question? [SwiftUI: is there exist modifier to highlight substring of Text() view?](https://stackoverflow.com/questions/59426359/swiftui-is-there-exist-modifier-to-highlight-substring-of-text-view) – Muhand Jumah Jul 20 '20 at 20:02
  • It was solved [here](https://stackoverflow.com/a/62976651/12299030) and original post [Highlight a specific part of the text in SwiftUI](https://stackoverflow.com/questions/62111551/highlight-a-specific-part-of-the-text-in-swiftui) – Asperi Jul 21 '20 at 04:16
  • Workes for me. Thank you very much. – iSoldier Jul 22 '20 at 20:15

0 Answers0