10 #import "NSDate+CalendarView.h" 11 #import "NSString+CalendarView.h" 17 NSCalendar *gregorianCalendar;
22 gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
35 NSMutableArray *ret = [[NSMutableArray alloc] initWithCapacity:32];
36 NSMutableArray *mealsInDay;
37 for (
int day=0; day<32; day++) {
38 mealsInDay = [[NSMutableArray alloc] init];
39 [ret addObject:mealsInDay];
42 gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
46 NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
47 [dateComponents setYear:currentYear];
48 [dateComponents setMonth:currentMonth];
50 NSDate *calendarMonthDate = [gregorianCalendar dateFromComponents:dateComponents];
56 if (nil == [meal consumeDate]) {
57 NSLog(
@"NutritionCalendarView.monthMeals: no consume date: %@", meal);
59 mealDay = [
self getDateDay:[meal consumeDate]];
60 NSLog(
@"NutritionCalendarView.monthMeals: mealDay: %ld", (
long)mealDay);
61 if ((0<mealDay)&&(31>=mealDay)){
62 [ret[mealDay] addObject:meal];
64 NSLog(
@"NutritionCalendarView.monthMeals: ERROR?");
71 - (NSInteger) getDateDay:(NSDate *)date
74 NSInteger mealDay = [gregorianCalendar component:(NSCalendarUnitDay) fromDate:date];
77 - (NSInteger) getDateMonth:(NSDate *)date
80 NSInteger
currentMonth = [gregorianCalendar component:NSCalendarUnitMonth fromDate:date];
84 - (NSInteger) getDateYear:(NSDate *)date
88 NSInteger
currentYear = [gregorianCalendar component:NSCalendarUnitYear fromDate:date];
91 - (void)drawRect:(CGRect)rect
98 CGContextRef context = UIGraphicsGetCurrentContext();
102 withAlignment:NSTextAlignmentFromCTTextAlignment(kCTTextAlignmentCenter)];
104 NSMutableArray *rects = [
super dayRects];
109 NSDictionary *attrs = attributesBlack;
110 CGRect rectText = rect.frame;
115 NSArray *dayMeals = [mMeals objectAtIndex:rect.value];
116 NSInteger nMealsInDay = [dayMeals count];
117 if (0 < nMealsInDay) {
124 [rect.str drawUsingRect:rectText withAttributes:attrs];
NSArray< Meal * > * findMealsThisMonthDate:(NSDate *findDate)
NSMutableArray * dayRects
NSArray< NSArray< Meal *> *> * monthMeals()
instancetype sharedInstance()
NSInteger getDateMonth:(NSDate *date)
void drawCircle:toContext:withColor:(CGRect rect, [toContext] CGContextRef *context, [withColor] UIColor *color)
NSInteger getDateDay:(NSDate *date)
NSArray< NSArray< Meal * > * > * mMeals
void drawRect:(CGRect rect)
Singleton interface to both core and remote data sources.
NSInteger getDateYear:(NSDate *date)
NSDictionary * generateAttributes:withFontSize:withColor:withAlignment:(NSString *fontName, [withFontSize] CGFloat fontSize, [withColor] UIColor *color, [withAlignment] NSTextAlignment textAlignment)