Giter Site home page Giter Site logo

lkcarlendarview's Introduction

LKCarlendarView

simple and quick‘ calendar

把以前写的日历控件改了改, 大家可以看看 里面的时间处理方式 个人觉得 比github上面 的其他的算法简单多了

主要代码 我加了下注释

-(void)reloadMonthViewDate
{
    NSDateComponents* dateComponents = [_currentMonth copy];
    dateComponents.day = 1;
    
    //获得当前月的第一天时间
    NSDate* firstDay =  [currentLKCalendar dateFromComponents:dateComponents];
    
    //获得第一天 是周几
    int firstWeekDay = [currentLKCalendar components:NSWeekdayCalendarUnit fromDate:firstDay].weekday;
    
    //获取第一天 在日历中的位置。。     (根据你的设置去换算周几) :_firstDayWeek 是可设置的
    int firstDayPosition = (firstWeekDay - _firstDayWeek + 8)%8;
    
    //第一行第一天  跟  当前月第一天    的差距天数
    int dayDiff = 1 - firstDayPosition + 1;
    
    int size = _dayViews.count;
    NSMutableArray* dateArray = [NSMutableArray arrayWithCapacity:size];
    for (int i=0;i<size; i++) {
        //剩下的简单了  将第一行第一天  不断的加一  然后 保存起来  就可以 获得整个月的 时间集合了
        dateComponents.day = dayDiff;
        NSDate* date = [currentLKCalendar dateFromComponents:dateComponents];
        [dateArray addObject:date];
        
        dayDiff ++;
    }
    [self.dates removeAllObjects];
    self.dates = [NSMutableArray arrayWithArray:dateArray];
    
    //有时间集合了 剩下的 就是显示了
    [self refreshMonthView];
}

加入了 随机 周几开始

lkcarlendarview's People

Contributors

li6185377 avatar

Watchers

James Cloos avatar  avatar

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.