I've setup an NSTextField
with text color as white, and the background color as (black despite not rendering the background color, so its transparent). All in Interface Builder.
The problem I am having is the cursor is black, and hardly visible. Does the cursor not represent the text color? Any ideas how I can fix this?
Otherwise, the NSTextField
looks like it cannot be edited.
Since in practice the NSText* returned by -currentEditor for an NSTextField is always an NSTextView*, I added the following code to my custom NSTextField subclass:
-(BOOL) becomeFirstResponder
{
BOOL success = [super becomeFirstResponder];
if( success )
{
// Strictly spoken, NSText (which currentEditor returns) doesn't
// implement setInsertionPointColor:, but it's an NSTextView in practice.
// But let's be paranoid, better show an invisible black-on-black cursor
// than crash.
NSTextView* textField = (NSTextView*) [self currentEditor];
if( [textField respondsToSelector: @selector(setInsertionPointColor:)] )
[textField setInsertionPointColor: [NSColor whiteColor]];
}
return success;
}
So if you're already replacing this class because you're doing custom background drawing, this might be a more encapsulated solution. Maybe there's even a way to move this up into NSCell, which would be cleaner since NSCell is the one doing the drawing and knowing the colors anyway.
NSTextField *textField = self.textField;
NSColor *insertionPointColor = [NSColor blueColor];
NSTextView *fieldEditor = (NSTextView*)[textField.window fieldEditor:YES
forObject:textField];
fieldEditor.insertionPointColor = insertionPointColor;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With