8

I am working on the Note app using SwiftUI. I want to highlight the selected text in TextField or in the TextEditor and get the highlighted text.

I searched a lot but don't find any solution. If anyone help, I am very thankful to him

Muhammad Farooq
  • 263
  • 3
  • 10
  • 1
    SwiftUI does not provide such feature for now (SwiftUI 2.0) - use instead UIKit controls. – Asperi Oct 27 '20 at 14:17
  • 1
    @Asperi Can you please explain how to use UIKIT control in SwiftUI – Muhammad Farooq Oct 27 '20 at 15:16
  • @MuhammadFarooq The idea is to use [UIViewRepresentable](https://developer.apple.com/documentation/swiftui/uiviewrepresentable) to allow UIKit controls in SwiftUI. See [this project](https://github.com/kyle-n/HighlightedTextEditor) for an example. – An Hoa Oct 31 '20 at 13:43
  • 1
    Can you provide an answer with details @Muhammad Farooq? – JerseyDevel Dec 03 '20 at 15:06
  • @Lkabo I am working on the SwiftUI. I want to select some text in the text field or text editor and highlight it. But the SwiftUI doesn't give the highlight feature But we can select some specific text in the UITextView and highlight it. I rendered the UITextView in the swiftui and got this feature. – Muhammad Farooq Dec 04 '20 at 12:49
  • @MuhammadFarooq I think he meant to answer your own question with a solution. Even thought SwiftUI solution still doesn't exist, your UIKit solution could be handy – C. Skjerdal Apr 25 '21 at 00:24

0 Answers0