Oct 24
Cocoa Tip: Turning Off Wordwrap
Posted by Kevin in Hot Cocoa on Oct 24th, 2008| icon3No Comments »

Ever wanted to have a textview that didn’t automatically have text wrap to the next line? You’d think it just be a checkbox option in Interface Builder, but it isn’t. (Hint hint, Apple) Luckily though all you need to do to turn it off is cut and paste some code.

[[myTextView enclosingScrollView] setHasHorizontalScroller:TRUE];
[myTextView setHorizontallyResizable:TRUE];
NSSize layoutSize = [myTextView maxSize];
layoutSize.width = layoutSize.height;
[myTextView setMaxSize:layoutSize];
[[myTextView textContainer] setWidthTracksTextView:FALSE];
[[myTextView textContainer] setContainerSize:layoutSize];

Just cut and paste that code into your awakeFromNib method and replace myTextView with the outlet for your textview and voila, no more wordwrap!