2

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.

4

1 回答 1

1

您不能更改 NSDatePicker 的格式。我设法在 NSDatePicker 上显示了一个 NSTextField。它需要 NSDatePicker 和 NSTextField 的子类。在 XIB 中连接它们并进行测试。

@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

@implementation MyTextField

- (NSView *)hitTest:(NSPoint)aPoint
{
    return nil;
}

@end
于 2016-03-14T10:41:24.430 回答