Firstly, there are many ways to implement a calendar. But most fill out and easily get the TapkuLibrary calendar http://github.com/devinross/tapkulibrary , and then implement this TapkuLibrary in your class file. After implementing the following code to display the calendar
headerFile.h
#import <UIKit/UIKit.h> #import "Libraries/TapkuLibrary/TKCalendarMonthView.h" @interface calendarViewController : UIViewController<TKCalendarMonthViewDelegate,TKCalendarMonthViewDataSource, UITextFieldDelegate> { TKCalendarMonthView *calendar; UITextField *txtField; } @property(nonatomic,retain)UITextField *txtField;
@end
implementationFile.h
// @ synthesize ..............
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { [self doAddAction]; return YES; } -(void)doAddAction { calendar=[[TKCalendarMonthView alloc] init]; calendar.frame=CGRectMake(0,0,calendar.frame.size.width,calendar.frame.size.height); calendar.delegate=self; calendar.dataSource=self; [self.view addSubview:calendar]; } #pragma mark - #pragma mark TKCalendarMonthViewDelegate methods - (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)d { NSDateFormatter *objDateFormatter = [[NSDateFormatter alloc] init]; [objDateFormatter setDateFormat:@"dd-MM-yyyy"]; NSLog(@"%@",[objDateFormatter stringFromDate:d]); } - (void)calendarMonthView:(TKCalendarMonthView *)monthView monthDidChange:(NSDate *)d { NSLog(@"calendarMonthView monthDidChange"); } #pragma mark - #pragma mark TKCalendarMonthViewDataSource methods - (NSArray*)calendarMonthView:(TKCalendarMonthView *)monthView marksFromDate:(NSDate *)startDate toDate:(NSDate *)lastDate { NSLog(@"calendarMonthView marksFromDate toDate"); NSLog(@"Make sure to update 'data' variable to pull from CoreData, website, User Defaults, or some other source.");
user1740951
source share