Reputation: 4214
I am trying to do something that would seem to be very simple and surprised to find no help or similar postings anywhere.
I want an NSDatePicker
, which I have setup in IB and bound to property, to display as full day and date like so:
Sunday, March 6 2016
I tried dropping a NSFormatter
on the Date Picker Cell, it seems to have no effect. No matter the settings, it always displays as:
3/12/2016
After a good deal of searching, I am about to set up a complex sequence of showing and hiding the control to use a NSTextfield
to display in its place. The idea being that the NSDatePicker
will become visible for editing only. I am sure that will work, it just seems so much trouble for no reason.
Is it possible to alter the formatting on the NSDatePicker
when it is not firstResponder
? Understanding that it needs to display in the default manner when editing, I just want it to display more like a label when not firstResponder
.
Upvotes: 2
Views: 362
Reputation: 15633
You can't change the formatting of NSDatePicker. I managed to display a NSTextField on top of the NSDatePicker. It requires subclasses of NSDatePicker and NSTextField. Connect them in the XIB and test.
@interface MyDatePicker ()
@property (weak) IBOutlet NSTextField *textField;
@end
@implementation MyDatePicker
- (BOOL)becomeFirstResponder
{
self.textField.hidden = YES;
return [super becomeFirstResponder];
}
- (BOOL)resignFirstResponder
{
self.textField.hidden = NO;
return [super resignFirstResponder];
}
@end
and
@implementation MyTextField
- (NSView *)hitTest:(NSPoint)aPoint
{
return nil;
}
@end
Upvotes: 1