Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// 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

This comment has been minimized.

Copy link
Owner Author

@chamons 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