Hey there, I want to make a focus mode in UITextView. I want highlight the current sentence you are editing and blur everything else. Is there a simple way to get the range of the sentence at selected range in UITextView? Something like .paragraphRange. I tried with .lineRange
but it returns the range of the paragraph also.
let sentenceRange = composeText.lineRange(for: TextView.selectedRange)
If I want to focus the paragraph, it works fine, either with .lineRange
or .paragraphRange
if (focus)
{
if let stringLength = noteTextView.text?.characters.count
{
// Defocus everything
noteTextView.textStorage.addAttribute(NSForegroundColorAttributeName, value: styles.titleTextColor().withAlphaComponent(0.10), range:NSMakeRange(0, stringLength))
let sentenceRange = composeText.lineRange(for: noteTextView.selectedRange)
// Focus
noteTextView.textStorage.addAttribute(NSForegroundColorAttributeName, value: styles.titleTextColor().withAlphaComponent(1), range: sentenceRange)
}