I've a NSView with a editable NSTextField
and multiple other subviews like NSView, NSSlider, NSImage etc.
resignFirstResponder
, but that does not seems to work. How can I do this?Suppose that you have a subclass of NSView called clickView1.h. In reference to this post, you can achieve your goal in No. 1 as follows.
- (void)mouseDown:(NSEvent *)event{
AppDelegate *appDelegate = (AppDelegate *)[NSApp delegate];
[appDelegate.window makeFirstResponder:nil];
}
As for No. 2, I don't understand the question.
For question 1, I agree with BlueTomato that you need to make something else first responder, not call resignFirstResponder
. For question 2, subclass NSTextFieldCell
, and in the subclass, have an override like this:
- (NSText *)setUpFieldEditorAttributes:(NSText *)textObj
{
[super setUpFieldEditorAttributes: textObj];
if ([textObj isKindOfClass: [NSTextView class]])
{
NSTextView* textView = (NSTextView*) textObj;
[textView setSelectedTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSColor redColor],
NSBackgroundColorAttributeName,
nil] ];
}
return textObj;
}
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