Skip to content

Instantly share code, notes, and snippets.

@chamons
Created April 8, 2015 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamons/41de8ef6a64059ffdfd1 to your computer and use it in GitHub Desktop.
Save chamons/41de8ef6a64059ffdfd1 to your computer and use it in GitHub Desktop.
//
// AppDelegate.m
// MachHack2
//
// Created by Chris Hamons on 3/20/15.
// Copyright (c) 2015 Chris Hamons. All rights reserved.
//
#import "AppDelegate.h"
@import AppKit;
@import QuickLook;
@import Quartz;
@import GLKit;
@import SecurityInterface;
@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSDatePicker * p = [NSDatePicker new];
p.frame = NSMakeRect(0, 0, 200, 200);
p.datePickerElements = NSYearMonthDatePickerElementFlag;
p.datePickerMode = NSSingleDateMode;
p.timeZone = NSTimeZoneNameStyleStandard;
p.datePickerStyle = NSClockAndCalendarDatePickerStyle;
p.bordered = false;
p.dateValue = [NSDate date];
p.delegate = self;
[self.window.contentView addSubview:p];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
- (void)datePickerCell:(NSDatePickerCell *)aDatePickerCell validateProposedDateValue:(NSDate **)proposedDateValue timeInterval:(NSTimeInterval *)proposedTimeInterval
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd"];
NSLog(@"Date is %@",[formatter stringFromDate:*proposedDateValue]);
}
@end
@chamons
Copy link
Author

chamons commented Apr 8, 2015

Add this to your h file

@interface AppDelegate : NSObject <NSApplicationDelegate, NSDatePickerCellDelegate>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment