GithubHelp home page GithubHelp logo

won21kr / pmcalendar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kovpas/pmcalendar

0.0 2.0 0.0 678 KB

Yet another calendar component for iOS. Compatible with iOS 4.0 (iPhone & iPad) and higher. Supports presenting as a popover and very flexible UI tuning. Default theme is inspired by https://github.com/ocrickard/OCCalendar

License: MIT License

pmcalendar's Introduction

PMCalendar v0.2

Yet another calendar component for iOS. Compatible with iOS 4.0 (iPhone & iPad) and higher.

UI is inspired by ocrickard's OCCalendarController. It's quite good component, but doesn't have some useful features which I wanted to see. Unfortunately OCCalendarController very hard to maintain, so I decided to create my own implementation.

PMCalendar supports selection of multiple dates within one or several months, appears as a popover (if you used UIPopoverController before, you'll find PMCalendar management very similar), supports orientation changes out of the box and does not require any third party frameworks.

PMCalendar uses iOS' CoreGraphics and CoreText frameworks.

It's definitely not bug-free, so if you're going to use PMCalendar in production, please test it hard ;)

Feel free to concact me in case of any questions or suggestions. If you feel you know how to improve PMCalendar don't hesitate to contact me or send a pull request.

Legal

PMCalendar is released under the MIT License.

Screenshots

Screenshot 1  Screenshot 2

Screenshot 3

Usage

  • Add PMCalendar directory to your Xcode project
  • Add CoreGraphics and CoreText frameworks to your project
  • #import "PMCalendar.h"
  • Create instance of PMCalendarController with specific theme name (see below) and size:
        PMCalendarController *calendarController = [[PMCalendarController alloc] initWithThemeName:@"my super theme name" andSize:CGSizeMake(300, 200)];
  • Or use defaults:
        // default theme name (default.plist) and size (see default.plist for details)
        PMCalendarController *calendarController = [[PMCalendarController alloc] init];
        // default theme name (default.plist) and specific size
        PMCalendarController *calendarController = [[PMCalendarController alloc] initWithSize:CGSizeMake(300, 200)];
        // specific theme name and default calendar size for this theme
        PMCalendarController *calendarController = [[PMCalendarController alloc] initWithThemeName:@"my super theme name"];
  • Implement PMCalendarControllerDelegate methods to be aware of controller's state change:
        - (BOOL)calendarControllerShouldDismissCalendar:(PMCalendarController *)calendarController;
        - (void)calendarControllerDidDismissCalendar:(PMCalendarController *)calendarController;
        - (void)calendarController:(PMCalendarController *)calendarController didChangePeriod:(PMPeriod *)newPeriod;
  • Don't forget to assign delegate!
        calendarController.delegate = self;
  • Present calendarController from a view (i.e. UIButton), so calendar could position itself during rotation:
         [calendarController presentCalendarFromView:pressedButton
                            permittedArrowDirections:PMCalendarArrowDirectionUp | PMCalendarArrowDirectionLeft
                                            animated:YES];
  • Or CGRect:
         [calendarController presentCalendarFromRect:CGRectMake(100, 100, 10, 10)
                                              inView:self.view
                            permittedArrowDirections:PMCalendarArrowDirectionUp | PMCalendarArrowDirectionLeft
                                            animated:YES];
  • Dismiss it:
         [calendarController dismissAnimated:YES];

PMPeriod

    @interface PMPeriod : NSObject

    @property (nonatomic, strong) NSDate *startDate;
    @property (nonatomic, strong) NSDate *endDate;

    /**
     * Creates new period with same startDate and endDate
     */
    + (id) oneDayPeriodWithDate:(NSDate *) date;

    + (id) periodWithStartDate:(NSDate *) startDate endDate:(NSDate *) endDate;

    - (NSInteger) lengthInDays;

    /**
     * Creates new period from self with proper order of startDate and endDate.
     */
    - (PMPeriod *) normalizedPeriod;

    @end

Implemented properties

    @property (nonatomic, assign) id<PMCalendarControllerDelegate> delegate;

Selected period

    @property (nonatomic, strong) PMPeriod *period;

TBI! Period allowed for selection

    @property (nonatomic, strong) PMPeriod *allowedPeriod;

Monday is a first day of week. If set to NO then Sunday is a first day

    @property (nonatomic, assign, getter = isMondayFirstDayOfWeek) BOOL mondayFirstDayOfWeek;

If NO, only one date can be selected. Otherwise, user can pan to select period

    @property (nonatomic, assign) BOOL allowsPeriodSelection;

If YES, user can long press on arrow to fast iterate through months

    @property (nonatomic, assign) BOOL allowsLongPressMonthChange;

Direction of the arrow (similar to UIPopoverController's arrowDirection)

    @property (nonatomic, readonly) PMCalendarArrowDirection arrowDirection;

Size of a calendar controller

    @property (nonatomic, assign) CGSize size;

Themes (beta!)

Themes allows you to create your own calendar component look without touching PMCalendar code. In theory... On practice current implementation is a compromise between flexibility and speed of drawing of the component. Therefore, some theme properties which you expect to be working does not work :).

However, current implementation is powerful enough to create for example something like this:

Apple calendar theme 1 Apple calendar theme 2

Themes documentation is in progress, so for now please use two examples ("default.plist" and "apple calendar.plist") as a refernce.

If you wish to share theme you created for PMCalendar, please contact me, I'll add it together with a link to your project :).

pmcalendar's People

Contributors

kovpas avatar

Watchers

 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.