How to disable text color in NSTextView?

367 views Asked by At

I have setup a NSColorPanel which I use to change the background color of a window. In the window there is also a NSTextView with some text in. The problem is that is that when I change the color of the background, the text color gets changed to into the same. I've tried finding ways to prevent this but with no success.

1

There are 1 answers

0
Daij-Djan On

Override the NSTextView changeColor: method and in that method, keep a outlet to the backgeoundView and instead of changing the textView's own color send it to the outlet:

IBOutlet NSView *changeColorTarget;

...

- (IBAction)changeColor:(id)sender {
    if(self.changeColorTarget) {    
        [NSApp sendAction:@selector(changeColor:) target:self.changeColorTarget forEvent:nil];
    } else {
        [super changeColor:sender];    
    }
}

--> that way the textview retains its original functionality except if you set the outlet