joeciou / jkcalendar Goto Github PK
View Code? Open in Web Editor NEWCalendar library for iOS
License: MIT License
Calendar library for iOS
License: MIT License
I need to start the week on a Monday rather than a Sunday as it is now.
Is is possible with the current codebase to change this somehow?
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
I want to perform an action when month change?
how can I do that ?
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
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
I use JKCalendarTableView. set the delegate. But the tableview delegate method didSelectRowAt method not called.....Please please help me out to solve this issue.
func calendar(_ calendar: JKCalendar, didChangedMonth month: JKMonth) {}
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.
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
I run my app with JKCalendar v1.1.0 in Xcode 10.1 then I got 3 error.
Could you fix it as soon as possible?
Hi, I want to show a different month on load as if I want to show July so it will show July, not the Current month.
Thanks in advance !!
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?
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
}
}
I am using tableview calendar when i choose next month date which is grayed, its return next date but not selectable show in UI.
How to Disable Specific Date in JKCalendar Swift ? can any one help me out
How do I change the font size of a date?
Hi, i want to show the month name under the dates. How can i get that?
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.
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)
}
}
`
Any plan to support RTL ?
The Calendar looks messy and the month title disappear when scrolling back
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.