Disabling and Enabling an NSTextView

Q: How do I disable and enable an NSTextView?

A: Currently there is no direct way to disable and re-enable an NSTextView. However, with a few lines of code you can implement this feature on your own. The sample code below best illustrates this by changing the selectable and editable attributes as well as its text color.

Listing 1: Disabling and Enabling NSTextView

-(void)enableTextView:(BOOL)enableIt
{
        [textView setSelectable: enableIt];
        [textView setEditable: enableIt];
        if (enableIt)
                [textView setTextColor: [NSColor controlTextColor]];
        else
                [textView setTextColor: [NSColor disabledControlTextColor]];
}

Document Revision History

DateNotes
2006-09-11First Version

Posted: 2006-09-11


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.