I had to draw a border in an NSTestField so I subclassed NSTextFied as (.h file):
#import <Cocoa/Cocoa.h>
#import "NSTextField+HTMLCategoryAdditions.h"
@interface SIGH_NSTextField : NSTextField
@property (readwrite,nonatomic) NSColor * borderColor;
- (void) drawRect: (NSRect) dirtyRect;
@end
In the ViewController.mm file I set the delegate as:
[_enterMacAddressTxtFieldOutlet setDelegate: self];
I use: - (void) controlTextDidChange: (NSNotification *) obj
to catch a change in the contents of the TextField string value.
In a method I make the following requests:
{ ...
[_enterMacAddressTxtFieldOutlet setBorderColor: [NSColor redColor]];
[_enterMacAddressTxtFieldOutlet setBordered: YES];
[_enterMacAddressTxtFieldOutlet drawRect: [_enterMacAddressTxtFieldOutlet frame]];
[_enterMacAddressTxtFieldOutlet updateCell: _enterMacAddressTxtFieldOutlet.cell];
[_enterMacAddressTxtFieldOutlet setNeedsDisplay];
...}
This nicely draws my border in red. But only if the textField looses focus. I want the TextField to be redrawn before it looses focus.
Is there a way to do this?
TIA
ClarkW