iOS 프로젝트에 DSLCalenderview
을 사용하고 있습니다. DSLCalenderview
의 날짜를 기입해야합니다. 나는 특정 날짜를 NSMutablearray
에 저장하고 날짜 개체와 비교합니다. DSLCalenderview
코드는 다음과 같습니다두 개의 NSDates를 컴파일하는 방법은 무엇입니까?
- (void)drawBackground {
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setTimeZone:[NSTimeZone systemTimeZone]];
//[dateformatter setLocale:[NSLocale currentLocale]];
[dateformatter setDateFormat:@"MMMM yyyy dd HH:mm:ss Z"];
if (self.selectionState == DSLCalendarDayViewNotSelected) {
user=[[NSUserDefaults alloc] init];
NSUInteger flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:flags fromDate:[self.day date]];
NSDateComponents *componentsOfToday = [calendar components:flags fromDate:[NSDate date]];
date = [calendar dateFromComponents:components];
dateToday = [calendar dateFromComponents:componentsOfToday];
if (self.isInCurrentMonth) {
/*
for (int i=0;i<datearray.count;i++) {
dateSelected=[dateformatter dateFromString:[datearray objectAtIndex:i]];
}
if ([date isEqualToDate:dateSelected]) {
NSLog(@"date selected......... %@",dateSelected);
}
*/
// NSLog(@">>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
if ([date isEqualToDate:dateToday]) {
// NSLog(@"inside today......... %@",dateToday);
[[UIColor redColor] setFill];
//from now current day is colored
}
else {
//NSLog(@"date selected %@",dateSelected);
[[UIColor colorWithWhite:245.0/255.0 alpha:1.0] setFill];
}
}
else {
// NSLog(@"++++++++++++++++++++++++++++++");
if ([date isEqualToDate:dateToday]) {
[[UIColor greenColor] setFill];
}
else {
[[UIColor colorWithWhite:225.0/255.0 alpha:1.0] setFill];
}
for (int i=0;i<datearray.count;i++) {
dateSelected=[dateformatter dateFromString:[datearray objectAtIndex:i]];
NSLog(@"date %@ dateselected %@",date,dateSelected);
NSDateComponents *selected=[calendar components:flags fromDate:dateSelected];
dateSelected=[calendar dateFromComponents:selected];
NSLog(@"date %@ dateselected %@",date,dateSelected);
if ([date isEqualToDate:dateSelected]) {
NSLog(@"inside loop");
[[UIColor grayColor]setFill];
}
}
}
UIRectFill(self.bounds);
}
else {
switch (self.selectionState) {
case DSLCalendarDayViewNotSelected:
NSLog(@"DSLCalendarDayViewNotSelected>>>>+++");
break;
case DSLCalendarDayViewStartOfSelection:
NSLog(@"DSLCalendarDayViewStartOfSelection>>>>+++");
[[[UIImage imageNamed:@"DSLCalendarDaySelection-left"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 20, 20, 20)] drawInRect:self.bounds];
break;
case DSLCalendarDayViewEndOfSelection:
NSLog(@"DSLCalendarDayViewEndOfSelection>>>>+++");
[[[UIImage imageNamed:@"DSLCalendarDaySelection-right"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 20, 20, 20)] drawInRect:self.bounds];
break;
case DSLCalendarDayViewWithinSelection:
NSLog(@"DSLCalendarDayViewWithinSelection>>>>+++");
[[[UIImage imageNamed:@"DSLCalendarDaySelection-middle"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 20, 20, 20)] drawInRect:self.bounds];
break;
case DSLCalendarDayViewWholeSelection:
NSLog(@" DSLCalendarDayViewWholeSelection");
NSLog(@"day select %@",selectedday);
[[NSUserDefaults standardUserDefaults] setObject:selectedday forKey:@"day"];
[[NSUserDefaults standardUserDefaults]synchronize];
[[[UIImage imageNamed:@"DSLCalendarDaySelection"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 20, 20, 20)] drawInRect:self.bounds];
break;
}
}
}
이 좀 봐 내 대답을 찾은 것 같아 : http://stackoverflow.com/questions/6112075/ios-compare-two-dates – Signo