Cue
Cue

Reputation: 3092

How to highlight text in a textView in Swift?

I would like to highlight a part of text in a UITextView like Pages for iOS or Safari for iOS do. I search the documentation but I can't find a way to do it, maybe because I'm a beginner in iOS development and I miss some crucial info. Somebody can help me?

Screenshot of Pages for iOS:

Pages for iOS

Screenshot of Safari for iOS:

Safari for iOS

Upvotes: 7

Views: 4741

Answers (1)

Duncan C
Duncan C

Reputation: 131398

If you only need to highlight a single, contiguous block of text you can set the selection programmatically. Your examples show multiple discontinuous parts however. For that you are going to need to use an attributed string. There is no other system-provided highlighting function. (There might be a third party library that offers this though - you'll have to search.)

Upvotes: 1

Related Questions