I would like to implement the Medium iOS App like effect for tapping highlight and shows tooltip.
I have been researching on Text Kit
and some other stackoverflow questions have some thoughts on it, please also suggest what's the better alternative to this.
Scenario:
Solution thoughts:
UITextView
for storing textNSBackgroundColorAttributedName
layoutManager.characterIndexForPoint(...)
AMPopTip
, CMPopTipView
, EasyTipView
Right now, I am not able to select the word and shows the tooltip just next to it. Any tier of help is appreciated.
After you added the package, all you need to do is import it and you can add a tooltip to any SwiftUI View in that file! As the first example, the Text view is provided as the tooltip content and it's attached to the other Text view. Below you can see the example of code that is required to create the tooltip and the result you see on the screen.
Lastly, if you want to select the entire paragraph, tap any word within the paragraph four times in quick succession. Once it’s highlighted, you’ll have access to cut, copy and paste tools located right above the selected portion. And that’s how the gestures for quick selecting texts on your iPhone and iPad work.
Triple-tap a word to select the sentence containing that word. This includes the trailing period. Quadruple-tap does the same as a double, only it selects the entire paragraph. One of the most annoying text-selection tasks in iOS is trying to copy a URL, a phone number or an email address. If those strings are on a webpage, good luck.
There are a few text-selection oddities in iOS 13. The most annoying is that, when you tap in the middle of a word, the text-selection cursor appears at either the end or the beginning of the word. On the Mac, if you click the cursor between the letters M and A of “Mac,” that’s where it goes.
Here is a way to Highlight text.
Create an IBOutlet named myLabel
In ViewDidLoad
type
let yourString = "This is how you highlight text"
myLabel.text = yourString
let malleableString = NSMutableAttributedString(string: yourString)
let numberOfCharactersToHighlight = 5
let startingIndex = 1
malleableString.addAttribute(NSBackgroundColorAttributeName, value: .magenta, range: NSRange(location: startingIndex, length: numberOfCharactersToHighlight))
myLabel.attributedText = malleableString
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With