Coder Social home page Coder Social logo

rkcalendar's Introduction

RKCalendar

RKCalendar is a SwiftUI Calendar / Date Picker for iOS and MacOS.

Features include:

  • minimum and maximum calendar dates selectable,
  • single date selection,
  • range of dates selection,
  • multi-dates selection,
  • disabled dates setting,
  • time selection,
  • horizontal view,
  • weekly view.

Light Mode

demo app first screenshot demo app first screenshot

Dark Mode

demo app first screenshot demo app first screenshot

Requirements

  • iOS 14+, MacOS 11+
  • Swift 5.3+

Installation

To install this version of RKCalendar via the official Swift Package Manager.

Select Xcode>File> Add Packages and use https://github.com/workingDog/RKCalendar

Usage

Typically create a RKManager and pass it to a RKCalendarView, for example:

import SwiftUI
import RKCalendar

struct ContentView : View {
    
    @State var showCalendar = false
    @StateObject var rkManager = RKManager(calendar: Calendar.current, minimumDate: Date().addingTimeInterval(-60*60*24*60), maximumDate: Date().addingTimeInterval(60*60*24*90), mode: .singleDate)
    
    var body: some View {
                Button(action: { showCalendar.toggle() }) {
                    Text("Example - Single Date Selection").foregroundColor(.blue)
                }
                .sheet(isPresented: $showCalendar) { 
                        RKCalendarView().environmentObject(rkManager) 
                }     
        }
    }
}

Calendar minimum and maximum date setting

Setting the calendar, minimum and maximum dates that can be selected.

RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*365), mode: .singleDate)

Single date selection

Use mode .singleDate to select a single date.

RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: maxDate, mode: .singleDate)

Range of dates selection

Use mode .dateRange to select a contiguous range of dates, from a start date to an end date.

RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: maxDate, mode: .dateRange)

Note, mode .dateRange is automatically toggled internally and the end date must be greater than the start date.

Multi-dates selection

Use mode .multiDate for selecting a number of dates.

RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: maxDate, mode: .multiDate)

Disabled-dates setting

Use any mode and set zero or more dates to be disabled (un-selectable).

For example:

var rkManager = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: maxDate, mode: .singleDate)

rkManager.disabledDates.append(contentsOf: [
    Date().addingTimeInterval(60*60*24*4),
    Date().addingTimeInterval(60*60*24*5),
    Date().addingTimeInterval(60*60*24*7)
])

Time selection

RKTimeView allows for a time (hh:mm) selection option on a long press.

Time selection is activated by setting displayTime=true in RKManager (default false). On a long press, a time selection view will popup allowing hours and minutes to be selected.
Time selection is available for all modes. For mode ".dateRange", select the start and end dates as usual with a tap, then with a long press, select the time desired.

Horizontal view

An horizontal view of the calendar is activated by setting isVertical=false in RKManager (default true).

Weekly view

An weekly view of the calendar is activated by setting isWeeklyView=true in RKManager (default false). Note you must also set isVertical=false. Currently only works with isContinuous=false, that is, horizontal paging only.

Language

The language of the calendar is activated by setting locale in RKManager (default Local.curent) to display the months and weeks in the chosen language.

Other options

The RKCalendar can be in two scrolling modes, a continuous mode to display a scrolling calendar of months, or a one month at a time (paging) scrolling view. This is activated by setting isContinuous in RKManager (default true).

RKCalendar can prevent a user input for the current mode by setting disabled=true in RKManager (default false).

Various elements of RKCalendar, such as the monthly headings, can be colored. This is achieved by customising the relevent RKManager.colors.

License

RKCalendar is available under the MIT license. See the LICENSE file for more info.

rkcalendar's People

Contributors

raffikian avatar workingdog avatar

Stargazers

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

Watchers

 avatar  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.