如何在Objective C中将星期的第一天设置为星期日?

时间:2016-11-08 18:47:43

标签: ios calendar nsdate

我正在尝试将日历显示为星期日作为一周的第一天。它目前定于星期一。任何人都可以看看这个代码并修复它?它来自GitHub上的自定义日历:https://github.com/jubinjacob19/CustomCalendar

谢谢

Calendar Screenshot

    NSDateComponents *components = [_gregorian components:_dayInfoUnits fromDate:_calendarDate];

components.day = 1;
NSDate *firstDayOfMonth         = [_gregorian dateFromComponents:components];
NSDateComponents *comps         = [_gregorian components:NSWeekdayCalendarUnit fromDate:firstDayOfMonth];

NSInteger weekdayBeginning      = [comps weekday];  // Starts at 1 on Sunday
weekdayBeginning -=2;
if(weekdayBeginning < 0)
    weekdayBeginning += 7;                          // Starts now at 0 on Monday

NSRange days = [_gregorian rangeOfUnit:NSDayCalendarUnit
                                inUnit:NSMonthCalendarUnit
                               forDate:_calendarDate];

0 个答案:

没有答案