optonaut / ActiveLabel.swift

UILabel drop-in replacement supporting Hashtags (#), Mentions (@) and URLs (http://) written in Swift
MIT License
4.47k stars 686 forks source link

Add links / mentions / hashtags without regex, but instead manually #319

Closed unixb0y closed 4 years ago

unixb0y commented 5 years ago

Hello, Is there any way to mark a specific portion of text as a link for example, without any "clues" in the text itself?
I get a server response which exactly tells me where specific things are and I used NSAttributedString for that before, since I can just specify the range that I got from the server and display that part of the text as e.g. a hyperlink. Somehow, the combination of UILabel.attributedText and ActiveLabel doesn't seem to work together (the attributes set on the NSAttributedString are ignored).

I would love a method like addURL(from: Int, to: Int) / addMention(from: Int, to: Int) etc.

unixb0y commented 5 years ago

I'm now using the "regex" thing and defining the complete string that I want to highlight as the regex 😅
Not very elegant and error-prone in case that character sequence appears another time somewhere else...

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.