Giter VIP home page Giter VIP logo

jkcalendar's Introduction

JKCalendar

Carthage compatible Version Platform Swift 3.x Swift 4.0

Screenshot

Requirements

  • iOS 9.0+
  • Xcode 8+

Installation

CocoaPods

To install add the following line to your Podfile:

pod 'JKCalendar'

Carthage

To install add the following line to your Cartfile:

github "JoeCiou/JKCalendar"

Usage

Firstley, import JKCalendar

import JKCalendar

Initialization

Then, there are to two ways you can create JKCalendar:

  • By storyboard, change class of any UIView to JKCalendar

Note: Set Module to JKCalendar.

  • By code, using initializer.
let calendar = JKCalendar(frame: frame)

Mark

public enum JKCalendarMarkType{
    case circle
    case hollowCircle
    case underline
    case dot
}

For single mark: For continuous mark:

Examples

Firstley, Setup data source:

calendar.dataSource = self

For single mark:

func calendar(_ calendar: JKCalendar, marksWith month: JKMonth) -> [JKCalendarMark]? {
    let today = JKDay(date: Date())
    if today == month{
        return [JKCalendarMark(type: .underline, day: today, color: UIColor.red)]
    }else{
        return nil
    }
}

For continuous mark:

func calendar(_ calendar: JKCalendar, continuousMarksWith month: JKMonth) -> [JKCalendarContinuousMark]?{
    let markStartDay = JKDay(year: 2017, month: 9, day: 3)!
    let markEndDay = JKDay(year: 2017, month: 9, day: 12)!
    if markStartDay == month || markEndDay == month{
        return [JKCalendarContinuousMark(type: .circle, start: markStartDay, end: markEndDay, color: UIColor.red)]
    }else{
        return nil
    }
}

License

The MIT License (MIT)

copyright (c) 2017 Joe Ciou

jkcalendar's People

Contributors

dungi avatar joeciou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jkcalendar's Issues

Compatibility with SDK iOS 12.1

I run my app with JKCalendar v1.1.0 in Xcode 10.1 then I got 3 error.

  • 'common' has been renamed to 'RunLoopMode.commonModes'
  • 'orientationDidChangeNotification' has been renamed to 'NSNotification.Name.UIDeviceOrientationDidChange'
  • 'orientationDidChangeNotification' has been renamed to 'NSNotification.Name.UIDeviceOrientationDidChange'

Could you fix it as soon as possible?

Didselect delegate method not called

I use JKCalendarTableView. set the delegate. But the tableview delegate method didSelectRowAt method not called.....Please please help me out to solve this issue.

Left and right content view background color not set when setting backgroundColor

It seems that when setting backgroundColor of the Calendar, leftContentView.backgroundColor and rightContentView.backgroundColor aren't set and so these have a default white background.

Simple fix I'm guessing would be to add them into the setter for backgroundColor:

public override var backgroundColor: UIColor? {
        set {
            topView?.backgroundColor = newValue
            weekView?.backgroundColor = newValue
            calendarPageView?.backgroundColor = newValue
            calendarPageView?.currentView?.backgroundColor = newValue
            footerView?.backgroundColor = newValue
            leftContentView.backgroundColor = newValue
            rightContentView.backgroundColor = newValue
        }

        get {
            return calendarPageView?.backgroundColor
        }
    }

Not show any Dates

Not shown any dates of Month in My new device 7+
Plz tell me what i do ?
image1

when loading scrollview based, everything gets stuck

when loading scrollview based, everything gets stuck
calendarScrollView = JKCalendarScrollView(frame: self.view.frame) view |+| calendarScrollView! calendarScrollView!.m_edges |=| view calendarScrollView!.calendar.delegate = self calendarScrollView!.calendar.dataSource = self // calendarScrollView!.calendar.textColor = UIColor(red: 60/255, // green: 60/255, // blue: 60/255, // alpha: 1) calendarScrollView!.calendar.backgroundColor = UIColor.white calendarScrollView!.calendar.focusWeek = JKCalendar.calendar.component(.weekOfMonth, from: selectDay.date) - 1 calendarScrollView!.calendar.isInitializationCollapsed = true

Failed to render and update auto layout status

Hello Joe, I got error failed to render and update auto layout status when add JKCalendar to storyboard. Is there any way to fix it? Is it okay for us to submit the app with error auto layout status?

Dates in calendar are all same day

In your example and the project I tried to implement JKCalendar the dates for the month are all the same number. For example, for the month of July, all dates are the 29th.

screen shot 2018-08-28 at 2 50 53 pm

Mark array of dates

Hello. I want to pass to calendar array of dates which should be checked. I try to use loop inside

func calendar(_ calendar: JKCalendar, marksWith month: JKMonth) -> [JKCalendarMark]? {
    
    for item in habbit.dates {
        print(item)

        let today = JKDay(date: item)
        if today == month {
            return [JKCalendarMark(type: .circle, day: today, color: .systemGreen)]
        }
    }
    return nil
    
}

but it doesn't work.

Why not use default class Date in swift?

Can you tell me why this lib don't use the default Date class in Swift (you can add extension for class Date), instead you build a custom class JKCalendarDay. What are the benefits of this custom class?

Thank you <3

Support RTL

Any plan to support RTL ?
The Calendar looks messy and the month title disappear when scrolling back

Personal Use advice(个人使用建议)

This custom calendar selection control is nice and COMPATIBLE with OC, so much the better.
这个自定义日历选择控件挺好的,能兼容OC那就更好了。

比如:主要是添加 @objc public关键字.

`//
// common.swift
//
// Copyright © 2017 Joe Ciou. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

import UIKit

@objc public class JKYear: NSObject, Comparable {
@objc public let year: Int

@objc public init?(year: Int) {
    if year < 0{
        return nil
    }
    self.year = year
}

@objc override public func isEqual(_ object: Any?) -> Bool {
    if let object = object as? JKYear{
        return object == self
    }else{
        return false
    }
}

public static func == (lhs: JKYear, rhs: JKYear) -> Bool {
    return lhs.year == rhs.year
}

public static func != (lhs: JKYear, rhs: JKYear) -> Bool {
    return lhs.year != rhs.year
}

public static func < (lhs: JKYear, rhs: JKYear) -> Bool {
    return lhs.year < rhs.year
}

public static func <= (lhs: JKYear, rhs: JKYear) -> Bool {
    return lhs.year <= rhs.year
}

public static func > (lhs: JKYear, rhs: JKYear) -> Bool {
    return lhs.year > rhs.year
}

public static func >= (lhs: JKYear, rhs: JKYear) -> Bool {
    return lhs.year >= rhs.year
}

}

@objc public class JKMonth: JKYear {
@objc public let month: Int

@objc public init?(year: Int = Date().year, month: Int = Date().month) {
    if month < 0 || month > 12 {  return nil  }
    self.month = month
    super.init(year: year)
}

@objc public var next: JKMonth {
    var year = self.year
    var month = self.month + 1
    if month > 12{
        year += 1
        month = 1
    }
    return JKMonth(year: year, month: month)!
}

@objc public var previous: JKMonth {
    var year = self.year
    var month = self.month - 1
    if month < 1 {
        year -= 1
        month = 12
    }
    return JKMonth(year: year, month: month)!
}

@objc public var firstDay: JKDay{
    return JKDay(year: year, month: month, day: 1)!
}

@objc public var lastDay: JKDay{
    let date = JKCalendar.calendar.date(byAdding: DateComponents(month: 1, day: -1), to: firstDay.date)!
    return JKDay(year: date.year, month: date.month, day: date.day)!
}

@objc public var daysCount: Int {
    return lastDay.day
}

@objc public var weeksCount: Int {
    return Int(ceil(Double(daysCount + firstDay.weekday - 1) / 7))
}

@objc public func weeks() -> [JKWeek] {
    var weeks: [JKWeek] = []
    let weekday = firstDay.weekday - 1
    var offsetDay = firstDay.previous(weekday)
    while offsetDay <= self {
        weeks.append(offsetDay.week())
        offsetDay = offsetDay.next(7)
    }
    return weeks
}

@objc public var name: String {
    guard let date = JKCalendar.calendar.date(from: DateComponents(year: year, month: month)) else {
        return ""
    }
    
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "MMMM"

    return dateFormatter.string(from: date)
}

@objc override public func isEqual(_ object: Any?) -> Bool {
    if let object = object as? JKMonth{
        return object == self
    }else{
        return false
    }
}

public static func == (lhs: JKMonth, rhs: JKMonth) -> Bool {
    return lhs.year == rhs.year && lhs.month == rhs.month
}

public static func != (lhs: JKMonth, rhs: JKMonth) -> Bool {
    return lhs.year != rhs.year || lhs.month != rhs.month
}

public static func < (lhs: JKMonth, rhs: JKMonth) -> Bool {
    return lhs.year < rhs.year || (lhs.year == rhs.year && lhs.month < rhs.month)
}

public static func <= (lhs: JKMonth, rhs: JKMonth) -> Bool {
    return lhs.year < rhs.year || (lhs.year == rhs.year && lhs.month <= rhs.month)
}

public static func > (lhs: JKMonth, rhs: JKMonth) -> Bool {
    return lhs.year > rhs.year || (lhs.year == rhs.year && lhs.month > rhs.month)
}

public static func >= (lhs: JKMonth, rhs: JKMonth) -> Bool {
    return lhs.year > rhs.year || (lhs.year == rhs.year && lhs.month >= rhs.month)
}

}

@objc public class JKDay: JKMonth {
@objc public let day: Int

@objc public init?(year: Int, month: Int, day: Int) {
    guard let _ = JKCalendar.calendar.date(from: DateComponents(year: year,
                                                                month: month,
                                                                day: day)) else {
        return nil
    }
    self.day = day
    super.init(year: year, month: month)
}

@objc convenience public init(date: Date) {
    let year = date.year
    let month = date.month
    let day = date.day
    self.init(year: year, month: month, day: day)!
}

@objc public var date: Date {
    return JKCalendar.calendar.date(from: DateComponents(year: year,
                                                         month: month,
                                                         day: day))!
}

@objc public var weekday: Int {
    return date.week
}

@objc public var weekOfMonth: Int {
    return date.weekOfMonth
}

@objc public var weekOfYear: Int {
    return date.weekOfYear
}

@objc public func week() -> JKWeek{
    return JKWeek(sunday: self.previous(weekday - 1))
}

@objc public func next(_ count: Int = 1) -> JKDay{
    let components = DateComponents(day: count)
    return JKDay(date: JKCalendar.calendar.date(byAdding: components, to: date)!)
}

@objc public func previous(_ count: Int = 1) -> JKDay{
    let components = DateComponents(day: -count)
    return JKDay(date: JKCalendar.calendar.date(byAdding: components, to: date)!)
}

@objc public func days(until: JKDay) -> [JKDay] {
    let (start, end) = self < until ? (self, until): (until, self)
    
    var days: [JKDay] = [start]
    var offsetDay = start
    
    while offsetDay != end {
        offsetDay = offsetDay.next()
        days.append(offsetDay)
    }
    return days
}

@objc override public func isEqual(_ object: Any?) -> Bool {
    if let object = object as? JKDay{
        return object == self
    }else{
        return false
    }
}

public static func == (lhs: JKDay, rhs: JKDay) -> Bool {
    return lhs.year == rhs.year && lhs.month == rhs.month && lhs.day == rhs.day
}

public static func != (lhs: JKDay, rhs: JKDay) -> Bool {
    return lhs.year != rhs.year || lhs.month != rhs.month || lhs.day != rhs.day
}

public static func < (lhs: JKDay, rhs: JKDay) -> Bool {
    return lhs.year < rhs.year ||
        (lhs.year == rhs.year && (lhs.month < rhs.month || (lhs.month == rhs.month && lhs.day < rhs.day)))
}

public static func <= (lhs: JKDay, rhs: JKDay) -> Bool {
    return lhs.year < rhs.year ||
        (lhs.year == rhs.year && (lhs.month < rhs.month || (lhs.month == rhs.month && lhs.day <= rhs.day)))
}

public static func > (lhs: JKDay, rhs: JKDay) -> Bool {
    return lhs.year > rhs.year ||
        (lhs.year == rhs.year && (lhs.month > rhs.month || (lhs.month == rhs.month && lhs.day > rhs.day)))
}

public static func >= (lhs: JKDay, rhs: JKDay) -> Bool {
    return lhs.year > rhs.year ||
        (lhs.year == rhs.year && (lhs.month > rhs.month || (lhs.month == rhs.month && lhs.day >= rhs.day)))
}

}

@objc public class JKWeek: NSObject{

@objc public let sunday: JKDay

@objc public var monday: JKDay{
    return sunday.next(1)
}

@objc public var tuesday: JKDay{
    return sunday.next(2)
}

@objc public var wednesday: JKDay{
    return sunday.next(3)
}

@objc public var thursday: JKDay{
    return sunday.next(4)
}

@objc public var friday: JKDay{
    return sunday.next(5)
}

@objc public var staturday: JKDay{
    return sunday.next(6)
}

@objc public init(sunday: JKDay) {
    self.sunday = sunday
}

@objc public func contains(_ day: JKDay) -> Bool {
    return day >= sunday && day <= staturday
}

}

public func == (lhs: JKWeek, rhs: JKWeek) -> Bool {
return lhs.sunday == rhs.sunday
}

public func != (lhs: JKWeek, rhs: JKWeek) -> Bool {
return lhs.sunday != rhs.sunday
}

@objc public enum JKCalendarViewStatus: Int {
case collapse = 0
case between
case expand
}

public extension Date {
var day: Int {
return JKCalendar.calendar.component(.day, from: self)
}

var week: Int {
    return JKCalendar.calendar.component(.weekday, from: self)
}

var month: Int {
    return JKCalendar.calendar.component(.month, from: self)
}

var year: Int {
    return JKCalendar.calendar.component(.year, from: self)
}

var weekOfMonth: Int {
    return JKCalendar.calendar.component(.weekOfMonth, from: self)
}

var weekOfYear: Int {
    return JKCalendar.calendar.component(.weekOfYear, from: self)
}

}

`

JKCalendarScrollView issues with month change

Hi,

First of all this is a great library and thanks for that.
I've used JKScrollview in my app and it works fine until expand and collapse happen.

When expand or collapse happen, calendar view month change is not changing (actually previous ad next functions triggers).

I've checked why is this happening and it seems like index issue. Could you please assists me on this issue how to resolve it.

Regards,
Isuru

JKDay convert to Date with wrong Date value

JKDay always give us Date with GMT+0 value even if I use it in GMT+7. So when I try to compare between today date that I got from system and the date that converted from JKDay it will always give us a false except we are in GMT+0 timezone.

min and max function return wrong value for JKDay object

Today i tried to use your control in my application and found small issue. I needed to get start and end days from two JKDay objects. I used something like following: min(day1, day2). but got wrong value, because this function use public static func < (lhs: JKYear, rhs: JKYear) -> Bool for base class JKYear. I fixed my issue using code day1 < day2 ? day1 : day2. in this case it use public static func < (lhs:... function from JKDay class.

How can i change first day of week?

Hi, i am using JKCalendar
But i really want to change the first day of week.
Currently, the first column is Sunday, i want to change to Monday.
Thanks

Cann't select Next month Date

I am using tableview calendar when i choose next month date which is grayed, its return next date but not selectable show in UI.

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.