0

I want to use the custom layout manager for a textview that is referenced from storyboard. I know that we can subclass the NSLayoutManager and assign the layout to textview in code but I want to use the textview from storyboard.

I found in NSTextcontainer class there is a method

func replaceLayoutManager(_ newLayoutManager: NSLayoutManager) to replace the layout manager

but I don't know how to use it for the textview created in the storyboard. kindly let me know is there is way to assign the custom layout manager for the textview created in storybard.

Shovo
  • 133
  • 2
  • 9
srividya
  • 419
  • 6
  • 16

1 Answers1

0

Can't you just add a reference to the text view in your view/view controller and call the replaceLayoutManager function on it?

Or don't you have any code connected to your storyboard? In that case you could subclass UITextView, override awakeFromNib and provide your custom layout manager in there. Then, use reference your subclass type in the storyboard.

fruitcoder
  • 1,073
  • 8
  • 24
  • 1
    on adding the replaceLayoutManager in awakeFromNib the application is crashing – srividya Mar 10 '21 at 14:12
  • What's the crash message? – fruitcoder Mar 11 '21 at 09:31
  • This causes a crash, at least on new iOS versions due to uncaught exception: `'*** -[NSLayoutManager glyphRangeForTextContainer:]: given container does not appear in the list of containers for this NSLayoutManager` When creating the text view programmatically (text container being created before the actual view) it works, but not through IB. – Tritonal Feb 16 '23 at 23:16