How to replace specific text by some visually specific entity in UITextView (like Xcode placeholders)

47 Views Asked by At

I know the title can be unclear, it's just because I don't know how to explain it better...

So here's what I try to achieve: I would like my user to type into a UITextView and, like in Xcode, if some pattern is detected, for instance <#TAG#>, display just the word TAG with a specific rounded cornered background color, and the user can only select the full word... Bonus, I would like to add a small SF Symbol before, that would be lovely.

So I've seen many tutorials with NSTextContainer and NSTextLayoutManager but what I've seen so far only permits me to change the color or the background of the whole <#TAG#> not replace by the word itself, nor prevent the user from selecting a part of it...

So if someone can point me in the good direction...

Example of <#TAG#> in Xcode

PS: Of course, I need the text to keep the whole <#TAG#>, not to simply replace it by TAG.

PPS: It needs to work on iOS 15+

0

There are 0 best solutions below