Disabling Line Wrapping in Large UITextViews

Hello,

I build an app which allows users to view code. As it exists today, we have line wrapping enabled on our UITextViews that house our code, but we would ideally like to be able to disable line-wrapping.

Our view hierarchy can be described as such:

We have UITableViewController whose cells contain a UIScrollView that then contains a UITextView. The UITextView has all of the contents of the code that the user is viewing.

It initially works fine, but after continuous, we frequently run into CoreAnimation memory allocation issues that result in flickering and poor scroll performance:

[Render] CoreAnimation: failed to allocate 3821632 bytes


Our cell is implemented pretty trivially:



The only bit of custom drawing we're doing here is related to drawing the line numbers in the leading gutter of the view, and that's being done in the layout manager. We still encounter memory allocation issues without the custom drawing.

After profiling using instruments, it seems that most of the work is being done in CGSColorMaskCopyARGB8888. I've also profiled for memory leaks, of which there are none.

I'd greatly appreciate some assistance in being able to efficiently implement a UITextView that doesn't have line-wrapping enabled. It seems to fall apart in this use case with nested scroll views and large code files with syntax highlighting.
It appears that the app is structured correctly for the intended behavior. The question itself is not about making UITextView not wrapping, correct?

Essentially, you want to configure the layout area defined NSTextContainer wide enough so that it doesn't wrap. You can do so by setting NSTextContainer.widthTracksTextView=false (and make the container size arbitrary wider). Then, by using the layout size, you should be able to use sizeThatFits: to calculate the text view width. UIScrollView should take care the rest of it.

If the issue persists after getting the ideal text view size, please file a bug for UITextView since there might be unintended view contents flattening happening in the configuration.

Unfortunately the issue still persists with the changes made above. I'll file a bug via the Feedback Assistant.
Disabling Line Wrapping in Large UITextViews
 
 
Q