我是 iOS 开发的新手(来自 Android 开发),我需要一些帮助。我正在使用Vurig 的库来显示自定义日历控件并在日历中标记多个日期。
问题是我想标记回历日期而不是公历。我怎样才能做到这一点?
到目前为止,我已经将回历日期转换为公历以在日历上标记日期,但它只标记一个日期,而我想在日历月中标记多个日期。
到目前为止的代码:
-(void)calendarView:(VRGCalendarView *)calendarView switchedToMonth:(int)month targetHeight:(float)targetHeight animated:(BOOL)animated {
NSArray *dates;
NSDate *date = [self addDates:calendarView andDay:6 andMonth:10];
// if (month==8){
// dates = [NSArray arrayWithObjects:[NSNumber numberWithInt:5],[NSNumber numberWithInt:25], nil];
// }
// if (month==9) {
// dates = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:5], nil];
//
// }
//if (month==[[NSDate date] month]) {
NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:( NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSWeekCalendarUnit) fromDate:date];
int gmonth = [dateComponents month];
if (month == gmonth) {
dates = [NSArray arrayWithObjects:date, nil];
}
[calendarView markDates:dates];
}
-(void)calendarView:(VRGCalendarView *)calendarView dateSelected:(NSDate *)date {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]]; [dateFormatter setDateFormat:@"dd MMMM"];
NSLog(@"Selected date = %@",[dateFormatter stringFromDate:date]);
//NSLog(@"Selected date = %@",date);
}
-(NSDate *)addDates:(VRGCalendarView *)calendarView andDay:(int)day andMonth:(int)month{
// Then create an Islamic calendar
NSCalendar *hijriCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSIslamicCalendar];
// And grab those date components for the same date
NSDateComponents *hijriComponents = [[NSDateComponents alloc] init];
hijriComponents.day = day;
hijriComponents.month = month;
hijriComponents.year = 1434;
NSDate *hdate = [hijriCalendar dateFromComponents:hijriComponents];
// Create a Gregorian Calendar
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
// Set up components of a Gregorian date
NSDateComponents *gregorianComponents = [gregorianCalendar components:(NSDayCalendarUnit |
NSMonthCalendarUnit |
NSYearCalendarUnit)
fromDate:hdate];
// Create the date
NSDate *date = [gregorianCalendar dateFromComponents:gregorianComponents];
NSLog(@"[In Hijri calendar ->] Date is %@", date);
return date;
}