I would like to change the text color to "red" when the NSTextField becomes active. All non-active text fields need to have "black" text.
Using the becomeFirstResponder method, I am able to change the text color to "red". However, when the text field looses focus, the text color remains "red". I need to the text color to change back to "black" once it is the non-active NSTextField. I tried the resignFirstResponder method but it doesn't change the text color back to "black".
Here's my code:
#import <Foundation/Foundation.h>
@interface MyTextField : NSTextField {
}
@end
and
#import "MyTextField.h"
@implementation MyTextField
- (BOOL)becomeFirstResponder {
if (![super becomeFirstResponder]) {
return NO;
} else {
[self setTextColor:[NSColor redColor]];
return YES;
}
}
- (BOOL)resignFirstResponder {
if (![super resignFirstResponder]) {
return NO;
} else {
[self setTextColor:[NSColor blackColor]];
return YES;
}
}
@end