iphone – 将日历添加到文本字段中单击ios

iphone – 将日历添加到文本字段中单击ios,第1张

概述我是iOS开发的新手.我需要在UITextField点击上添加日历.如何添加自定义日历,因为我不想添加UIDatePicker. 首先以多种方式实现Calendar.但是TapkuLibrary http://github.com/devinross/tapkulibrary最常填充并且易于获取日历,然后在您的类文件中实现此TapkuLibrary.实现以下代码后显示日历 headerFile.h 我是iOS开发的新手.我需要在UITextFIEld点击上添加日历.如何添加自定义日历,因为我不想添加UIDatePicker.解决方法 首先以多种方式实现Calendar.但是Tapkulibrary http://github.com/devinross/tapkulibrary最常填充并且易于获取日历,然后在您的类文件中实现此Tapkulibrary.实现以下代码后显示日历

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;

@结束

implementationfile.h

// @synthesize …………..

- (BOol)textFIEldShouldBeginEditing:(UITextFIEld *)textFIEld{   [self doAddAction];       return YES;}-(voID)doAddAction{    calendar=[[tkcalendarMonthVIEw alloc] init];    calendar.frame=CGRectMake(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.");    // When testing initially you will have to update the dates in this array so they are visible at the    // time frame you are testing the code.    NSArray *data = [NSArray arrayWithObjects:                     @"2011-01-01 00:00:00 +0000",@"2011-01-09 00:00:00 +0000",@"2011-01-22 00:00:00 +0000",@"2011-01-10 00:00:00 +0000",@"2011-01-11 00:00:00 +0000",@"2011-01-12 00:00:00 +0000",@"2011-01-15 00:00:00 +0000",@"2011-01-28 00:00:00 +0000",@"2011-01-04 00:00:00 +0000",@"2011-01-16 00:00:00 +0000",@"2011-01-18 00:00:00 +0000",@"2011-01-19 00:00:00 +0000",@"2011-01-23 00:00:00 +0000",@"2011-01-24 00:00:00 +0000",@"2011-01-25 00:00:00 +0000",@"2011-02-01 00:00:00 +0000",@"2011-03-01 00:00:00 +0000",@"2011-04-01 00:00:00 +0000",@"2011-05-01 00:00:00 +0000",@"2011-06-01 00:00:00 +0000",@"2011-07-01 00:00:00 +0000",@"2011-08-01 00:00:00 +0000",@"2011-09-01 00:00:00 +0000",@"2011-10-01 00:00:00 +0000",@"2011-11-01 00:00:00 +0000",@"2011-12-01 00:00:00 +0000",nil];    // Initialise empty marks array,this will be populated with TRUE/FALSE in order for each day a marker should be placed on.    NSMutableArray *marks = [NSMutableArray array];    // Initialise calendar to current type and set the timezone to never have daylight saving    NSCalendar *cal = [NSCalendar currentCalendar];    [cal setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];    // Construct DateComponents based on startDate so the iterating date can be created.    // Its massively important to do this assigning via the NSCalendar and NSDateComponents because of daylight saving has been removed    // with the timezone that was set above. If you just used "startDate" directly (IE,NSDate *date = startDate;) as the first    // iterating date then times would go up and down based on daylight savings.    NSDateComponents *comp = [cal components:(NSMonthCalendarUnit | NSMinuteCalendarUnit | NSYearCalendarUnit |                                              NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSSecondCalendarUnit)                                    fromDate:startDate];    NSDate *d = [cal dateFromComponents:comp];    // Init offset components to increment days in the loop by one each time    NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];    [offsetComponents setDay:1];    // for each date between start date and end date check if they exist in the data array    while (YES) {        // Is the date beyond the last date? If so,exit the loop.        // NSOrderedDescending = the left value is greater than the right        if ([d compare:lastDate] == NSOrderedDescending) {            break;        }        // If the date is in the data array,add it to the marks array,else don't        if ([data containsObject:[d description]]) {            [marks addobject:[NSNumber numberWithBool:YES]];        } else {            [marks addobject:[NSNumber numberWithBool:NO]];        }        // Increment day using offset components (IE,1 day in this instance)        d = [cal dateByAddingComponents:offsetComponents toDate:d options:0];    }    [offsetComponents release];    return [NSArray arrayWithArray:marks];}
总结

以上是内存溢出为你收集整理的iphone – 将日历添加到文本字段中单击ios全部内容,希望文章能够帮你解决iphone – 将日历添加到文本字段中单击ios所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1011040.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存