Adding Custom NSLayoutManager to UItextView that is created in Storyboard

466 views Asked by At

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.

1

There are 1 answers

3
fruitcoder On

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.