Code Monkey home page Code Monkey logo

Comments (2)

ranjith1109 avatar ranjith1109 commented on July 26, 2024

Hi i fixed the above issue by editing two functions as below
This is to fix the day name :

- (void) _setupView{
    	self.nowLineView = [[TKNowView alloc] init];
	NSDateComponents *info = [[NSDate date] dateComponentsWithTimeZone:self.calendar.timeZone];
    info.weekday = 2;
	info.hour = info.minute = info.second = 0;
	self.formatter = [[NSDateFormatter alloc] init];
    self.formatter.timeZone = self.calendar.timeZone;
	self.eventGraveYard = [NSMutableArray array];
    self.backgroundColor = [UIColor whiteColor];
    self.clipsToBounds = YES;
    self.pages = [NSMutableArray arrayWithCapacity:3];
    self.weekdayPages = [NSMutableArray arrayWithCapacity:3];
    [self addSubview:self.horizontalScrollView];
	info.day -= 1;
	for(NSInteger i=0;i<3;i++){
		NSDate *date = [NSDate dateWithDateComponents:info];
		CGRect r = CGRectInset(self.horizontalScrollView.bounds, HORIZONTAL_PAD, 0);
		r.origin.x = CGRectGetWidth(self.horizontalScrollView.frame) * i + HORIZONTAL_PAD;
		r.origin.y = 0;
		CGRect rr = r;
		rr.origin.x = 0;
		UIScrollView *sv = [[UIScrollView alloc] initWithFrame:r];
		sv.autoresizingMask = UIViewAutoresizingFlexibleWidth;
		sv.clipsToBounds = NO;
		sv.tag = i;
		sv.contentSize = CGSizeMake(0, TIMELINE_HEIGHT);
		sv.alwaysBounceVertical = TRUE;
		sv.backgroundColor = [UIColor whiteColor];
		[self.horizontalScrollView addSubview:sv];
		TKTimelineView *timelineView = [[TKTimelineView alloc] initWithFrame:sv.bounds];
		timelineView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
		[sv addSubview:timelineView];
		timelineView.date = date;
		[self.pages addObject:sv];
		info.day += 1;
	}
	self.currentDay = [self _timelineAtIndex:1].date;
    [self _updateDateLabel];
    [self addSubview:self.daysBackgroundView];
    [self addSubview:self.monthYearLabel];
	NSInteger cnt = 0;    
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];    
    dateFormat.dateFormat = @"eee";    
    dateFormat.timeZone = self.timeZone;    
    NSDateComponents *sund = [[NSDateComponents alloc] init];    
    sund.day = 5;    
    sund.month = 12;    
    sund.year = 2010;    
    sund.hour = sund.minute = sund.second = sund.weekday = 0;    
    sund.timeZone = self.timeZone;    
    NSString * sun = [dateFormat stringFromDate:[NSDate dateWithDateComponents:sund]];    
    sund.day = 6;
    NSString *mon = [dateFormat stringFromDate:[NSDate dateWithDateComponents:sund]];    
    sund.day = 7;
    NSString *tue = [dateFormat stringFromDate:[NSDate dateWithDateComponents:sund]];    
    sund.day = 8;
    NSString *wed = [dateFormat stringFromDate:[NSDate dateWithDateComponents:sund]];    
    sund.day = 9;
    NSString *thu = [dateFormat stringFromDate:[NSDate dateWithDateComponents:sund]];
    sund.day = 10;
    NSString *fri = [dateFormat stringFromDate:[NSDate dateWithDateComponents:sund]];    
    sund.day = 11;
    NSString *sat = [dateFormat stringFromDate:[NSDate dateWithDateComponents:sund]];    
    NSArray *ar;
    if(self.sunday) ar = @[sun,mon,tue,wed,thu,fri,sat];
    else ar = @[mon,tue,wed,thu,fri,sat,sun];    
	NSInteger per = CGFrameGetWidth(self) - (DAY_LABEL_WIDTH *7);
	per /= 7;
	NSInteger minX = per / 2;	
	for(NSString *str in ar){		
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(minX + cnt*(DAY_LABEL_WIDTH+per) , 0, DAY_LABEL_WIDTH, 20)];        
        if ([str isEqualToString:@"Sun"]) {
            label.accessibilityLabel = @"Sunday";
        }
        else if ([str isEqualToString:@"Mon"]) {
            label.accessibilityLabel = @"Monday";
        }
        else if ([str isEqualToString:@"Tue"]) {
            label.accessibilityLabel = @"Tuesday";
        }
        else if ([str isEqualToString:@"Wed"]) {
            label.accessibilityLabel = @"Wednesday";
        }
        else if ([str isEqualToString:@"Thu"]) {
            label.accessibilityLabel = @"Thursday";
        }
        else if ([str isEqualToString:@"Fri"]) {
            label.accessibilityLabel = @"Friday";
        }
        else if ([str isEqualToString:@"Sat"]) {
            label.accessibilityLabel = @"Saturday";
        }
		label.font = [UIFont systemFontOfSize:10];
        label.text = [str substringToIndex:1];		
        label.textColor = cnt == 0 || cnt == 6 ? WEEKEND_TEXT_COLOR : [UIColor blackColor];		
        label.textAlignment = NSTextAlignmentCenter;		
        label.userInteractionEnabled = NO;		
        [self.daysBackgroundView addSubview:label];		
        [label sizeToFitWithAlignment];
		cnt++;
	}	
	[self.daysBackgroundView addSubviewToBack:self.daysScrollView];	
	UIView *dayContainerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.daysScrollView.contentSize.width, CGRectGetHeight(self.daysScrollView.frame))];    
	[self.daysScrollView addSubview:dayContainerView];	
	CGRect weekFrame = self.daysScrollView.frame;	
    weekFrame.origin = CGPointZero;	
    for(NSInteger i=0;i<3;i++){		
		weekFrame.origin.x = CGRectGetWidth(weekFrame) * i;	
        TKWeekdaysView *weekdayView = [[TKWeekdaysView alloc] initWithFrame:weekFrame];		
		for(UILabel *label in weekdayView.weekdayLabels){		
            label.userInteractionEnabled = YES;			
            [label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapWeekdayLabel:)]];
		}		
        [dayContainerView addSubviewToBack:weekdayView];
        [self.weekdayPages addObject:weekdayView];
	}
}

This is to fix the dates :
- (void) _setupDaysView{
	NSArray *labels =  [self _allDayLabels];
    NSDateComponents *comp = [self.calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitEra | NSCalendarUnitWeekday fromDate:self.currentDay];
    NSDateComponents *mutedCom = [self.calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitEra fromDate:self.currentDay];
    for(NSInteger cnt= comp.weekday + 5;cnt>=0;cnt--){
        NSDate *aDate = [self.calendar dateFromComponents:mutedCom];
        mutedCom = [self.calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitEra fromDate:aDate];
        TKDateLabel *label = labels[cnt];
        label.text = [NSString stringWithFormat:@"%@",@(mutedCom.day)];
        label.date = aDate;
        label.today = [aDate isTodayWithTimeZone:self.calendar.timeZone];
        label.selected = [aDate isSameDay:self.currentDay timeZone:self.calendar.timeZone];
        mutedCom.day --;
	}
	mutedCom = [self.calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitEra fromDate:self.currentDay];
	for(NSInteger cnt= comp.weekday + 5;cnt<labels.count;cnt++){
		NSDate *aDate = [self.calendar dateFromComponents:mutedCom];
        mutedCom = [self.calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitEra fromDate:aDate];
        TKDateLabel *label = labels[cnt];
        label.text = [NSString stringWithFormat:@"%@",@(mutedCom.day)];
        label.date = aDate;
        label.today = [aDate isTodayWithTimeZone:self.calendar.timeZone];
        label.selected = [aDate isSameDay:self.currentDay timeZone:self.calendar.timeZone];
        mutedCom.day ++;
	}
	self.indexOfCurrentDay = comp.weekday-1;
}

I jus tried this and it worked out but if possible explain me the logic in the _setupDaysView function.Thank you.

from tapkulibrary.

richardtop avatar richardtop commented on July 26, 2024

@ranjith1109 I've made a library which gets first day of the week from user's current locale automatically:
https://github.com/richardtop/CalendarKit

from tapkulibrary.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.