ios - 如何实现两周模式的日历 View (使用JTCalendar示例)

标签 ios iphone calendar icalendar dayofweek

enter image description here我已经实现了 JTCalendar View 来获取月 View 和周 View ,但在周 View 中,我需要获取两周 View 。建议我编码。

JTCalendar 代码:

CGFloat x = 0;
CGFloat width = self.frame.size.width / 7.;

CGFloat height = self.frame.size.height;

if(self.calendarManager.calendarAppearance.readFromRightToLeft)
{
    for(UIView *view in [[self.subviews reverseObjectEnumerator] allObjects])
    {
        view.frame = CGRectMake(x, 0, width, height);
        x = CGRectGetMaxX(view.frame);
    }
}
else{
    for(UIView *view in self.subviews)
    {
        view.frame = CGRectMake(x, 0, width, height);
        x = CGRectGetMaxX(view.frame);
    }
}

[super layoutSubviews];

#//weeksToDisplay

  • (void)configureConstraintsForSubviews
{
CGFloat weeksToDisplay;

if(cacheLastWeekMode)
{
    weeksToDisplay = 1 ;
}
else{
    weeksToDisplay = (CGFloat)(WEEKS_TO_DISPLAY + 1); // + 1 for weekDays
}

CGFloat y = 0;
CGFloat width = self.frame.size.width;
CGFloat height = self.frame.size.height / weeksToDisplay;

for(int i = 0; i < self.subviews.count; ++i){
    UIView *view = self.subviews[i];

    view.frame = CGRectMake(0, y, width, height);
    y = CGRectGetMaxY(view.frame);

    if(cacheLastWeekMode && i == weeksToDisplay + 1){
        height = 0.;
    }
}
}

最佳答案

在月 View 中更改周数显示为 3 还要在委托(delegate)方法 setBeginingofmonth 中注释以下代码

 for(JTCalendarWeekView *view in weeksViews)
{
    view.currentMonthIndex = currentMonthIndex;
    [view setBeginningOfWeek:currentDate];

    NSDateComponents *dayComponent = [NSDateComponents new];
    dayComponent.day = 7;

    currentDate = [calendar dateByAddingComponents:dayComponent toDate:currentDate options:0];

    // Doesn't need to do other weeks
//        if(self.calendarManager.calendarAppearance.isWeekMode)
//        {
//            break;
//        }
    }

在 JTCalendar updatePage 方法中将 7 更改为 14,如下

 if(!self.calendarAppearance.isWeekMode)
{
    dayComponent.month = currentPage - (NUMBER_PAGES_LOADED / 2);
}
else
{
    //to show next starting week for two weeks mode put 14
    dayComponent.day = 14 * (currentPage - (NUMBER_PAGES_LOADED / 2));
}

关于ios - 如何实现两周模式的日历 View (使用JTCalendar示例),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29160361/

相关文章:

iphone - ibtool 错误无法打开共享功能内存 GSCapability(没有此类文件或目录)

sql - SSRS 日历每个月的 6 周 7 天范围

android - 如果有日历事件更新,如何从 Android 设备获取信息?

c# - 如何在 C# 中编写 Apple 推送通知提供程序?

iphone - 如何自定义 UITableViewCell 而不会在 UITableView 中出现任何卡住

ios - 如果应用程序在区域内启动,startMonitoringForRegion 不会调用 didEnterRegion

java - 获取一天的总小时数

ios - FontAwesome Pro 和 xamarin.ios 只有一种字体可以激活

ios - 如何分组 PFObjects ?解析/swift

iphone - 如何按整数对数组进行排序