Giter VIP home page Giter VIP logo

calendarview's Introduction

CalendarView

[![CI Status](http://img.shields.io/travis/Nate Armstrong/CalendarView.svg?style=flat)](https://travis-ci.org/Nate Armstrong/CalendarView) Version License Platform

Usage

To run the example project, clone the repo, and run pod install from the CalendarViewDemo directory first.

Requirements

  • iOS 8.3+
  • Xcode 6.3

Installation

CalendarView is available through Carthage and CocoaPods. To install it, simply add the following line to your Podfile:

pod "CalendarView"

Screenshot

   

Usage

Use the CalendarView class in code:

let calendar = CalendarView(frame: CGRectMake(0, 0, CGRectGetWidth(view.frame), 320))
view.addSubview(calendar)

or as an outlet (supports auto layout)

@IBOutlet weak var calendar: CalendarView!

Select specific date

The selected date is the current date by default. You can select any date by using the selectDate(date: Moment) method.

let date: NSDate = MY_NSDATE
calendar.selectDate(moment(date))

Delegate

A CalendarView's delegate is notified of two events:

calendarDidSelectDate(date: Moment) // called when user taps a date
calendarDidPageToDate(date: Moment) // called when users swipes month

The CalendarView class uses SwiftMoment for date manipulation.

Example use of delegate calls

extension ViewController: CalendarViewDelegate {

  func calendarDidSelectDate(date: Moment) {
    title = date.format(dateFormat: "MMMM d, yyyy")
  }

  func calendarDidPageToDate(date: Moment) {
    title = date.format(dateFormat: "MMMM d, yyyy")
  }

}

Customizations

The aim is to allow the calendar to be as customizable as possible without making it overly complex and bloated.

Appearance

You can customize the look of the calendar by setting certain class properties of CalendarView.

import UIKit
import CalendarView

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?


  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Calendar appearance
    CalendarView.daySelectedBackgroundColor = UIColor.secondaryColor()
    CalendarView.daySelectedTextColor = UIColor.whiteColor()
    CalendarView.todayBackgroundColor = UIColor(white: 0.0, alpha: 0.3)
    CalendarView.todayTextColor = UIColor.whiteColor()
    CalendarView.otherMonthBackgroundColor = UIColor.clearColor()
    CalendarView.otherMonthTextColor = UIColor(white: 1.0, alpha: 0.3)
    CalendarView.dayTextColor = UIColor(white: 1.0, alpha: 0.6)
    CalendarView.dayBackgroundColor = UIColor.clearColor()
    CalendarView.weekLabelTextColor = UIColor(white: 1.0, alpha: 0.3)

    return true
  }
}

Selected date on swipe

By default the first day of the month is automatically selected when the user swipes to a different month. You can customize this behavior by modifying the selectedDayOnPaged property of your CalendarView instance:

public var selectedDayOnPaged: Int? = 1

If set to nil, no day will be automatically selected on swipe.

Author

Nate Armstrong, [email protected]

License

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

calendarview's People

Contributors

armstrongnate avatar multinerd avatar tehp avatar

Watchers

James Cloos 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.