I originally asked this question. I had assumed that the reason for the slow load time of my custom view was because of layering multiple views on top of each other or perha
The bottleneck is the selectable
property of your UITextView. There is an inexplicable performance issue in the creation of a UITextView with selectable
set to its default value of true.
The easiest way to work around the problem is to add your text view using the storyboard, making sure that you untick the selectable
property. There appears to be no documented way to create an unselectable text view in code (as setting selectable to false after creation does not avoid the performance issue during creation). If you need a selectable text view, first create an unselectable text view, and then set selectable to true in viewDidAppear
.
If you can't use the storyboard, you might want to consider using a third party class such as TTTAttributedLabel.
It looks like Apple uses a private API to avoid this problem. Other enterprising developers have discovered that, in ChatKit, text views appear to be created using a private method called initReadonlyAndUnselectableWithFrame:textContainer:
.