You can access the layout manager with textView.layoutManager
. You can assign your own layout manager by creating all the objects yourself:
NSTextStorage* textStorage = [[NSTextStorage alloc] initWithString:string];
// you could create a subclass of NSLayoutManager here
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
[textStorage addLayoutManager:layoutManager];
self.textContainer = [[NSTextContainer alloc] initWithSize:self.view.bounds.size];
[layoutManager addTextContainer:self.textContainer];
UITextView* textView = [[UITextView alloc] initWithFrame:self.view.bounds textContainer:self.textContainer];
[self.view addSubview:textView];
However if you're trying to do syntax highlighting that is not the approach I would take. I suggest subclassing UITextView
to detect changes made by the user, and adding your own syntax highlighting at that point via [self.storage addAttributes:range:]
It probably would not be very hard to port this class I wrote from OS X to iOS: https://github.com/abhibeckert/Dux/blob/master/Dux/DuxSyntaxHighlighter.m — it applies syntax highlighting to an NSTextStorage, with good performance and support for a variety of languages.