1

I have been creating a highlighting system for my text view which is big enough to have scrolling enabled, at the bottom I have added a button using a subview which acts as a segue to the next view.

When I change the text with the function below the button disappears (not clickable or visible). When I scroll to the top of the text view and then scroll down again, the button reappears. Anyone knows why? Is there any way to refresh the display of the button?

Edit: The subview count does not change before or after the event.

func highlightText () {

    guard let text = self.textView.attributedText else {
        return
    }
    guard let range = self.textView.visibleBottomRange else {
        return
    }
    let attributedString = NSMutableAttributedString(attributedString:text)
    attributedString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.yellow , range: range)

    self.textView.attributedText = attributedString
}

1 Answers1

0

Found the answer here: Stackoverflow question

using: self.textView.layoutManager.allowsNonContiguousLayout = false; allows the subview to stay visible while changing the attributed text of text view