Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a custom NSTextStorage to a UITextView object created from a storyboard?

I want to set a custom NSTextStorage to a UITextView object created from a storyboard. If it's really needed I can consider subclassing of UITextView.

(I know if I created a UITextView object from the code I would be able to use a init(frame: CGRect, textContainer: NSTextContainer?) constructor.)

Swift is preferable.

like image 550
Artem Stepanenko Avatar asked Nov 22 '25 23:11

Artem Stepanenko


1 Answers

This works for me:

final class SendTextViewController: BaseViewController {
    @IBOutlet private var textView: UITextView!
    private var textStorage = MentionTextStorage()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        textView.textStorage.removeLayoutManager(textView.layoutManager)
        textStorage.addLayoutManager(textView.layoutManager)
     }
}
like image 70
Nguyễn Quang Avatar answered Nov 24 '25 22:11

Nguyễn Quang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!