Git Product home page Git Product logo

ios-calendar's Introduction

Introduction

ios-calendar is a stylable month calendar view for use in iPhone applications.

It has two branches:

  • three20 uses Three20 framework for styling
  • master allows you customize it without using Three20. It uses Nimbus, so it’s good idea to use Nimbus CSS for styling.

Note that README right now is a bit out of date and applies mostly to three20 branch, however the demo and tests are up-to-date.

While there are existing implementations (Kal and TKCalendarMonthView from Tapku Library, they are quite limited. In particular they both replicate styling and functionality of iPhone Calendar app and there is basically no easy way to adjust them. In addition to this – only portrait view is supported in them.

ios-calenar was developed to solve aforementioned problems. It’s default design is heavily inspired by MoMa iPhone app.

I maintain a list of apps using ios-calendar, feel free to add your app to it.

Project setup

While not elegant at all, currently the best method to add ios-calendar to your project is just to drop its source code in it (from “Calendar” group).
It is possible to use it as dependency, but only when your project doesn’t itself use Three20. Otherwise build results in XCode crash. I’m looking for suggestions on how better to resolve this issue.

Usage sample

XCode project on GitHub contains sample target – CalendarDemo. Here are main highlights:

CalendarDemoViewController.m

#import "CalendarDemoViewController.h"

#import <Three20UICommon/Three20UICommon+Additions.h>

@implementation CalendarDemoViewController

@synthesize calendarView;

- (void) loadView {
    [super loadView];

    self.calendarView = [[CXCalendarView new] autorelease];
    [self.view addSubview: self.calendarView];
    self.calendarView.frame = self.view.bounds;
    self.calendarView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    self.calendarView.selectedDate = [NSDate date];

    self.calendarView.delegate = self;
}

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {
    return YES;
}

#pragma mark CXCalendarViewDelegate

- (void) calendarView: (CXCalendarView *) calendarView
        didSelectDate: (NSDate *) date {

    NSLog(@"Selected date: %@", date);
    TTAlert([NSString stringWithFormat: @"Selected date: %@", date]);
}

@end

CalendarDemoAppDelegate.m

There is one very important thing to do in app delegate – set up Three20 styling. There is sample stylesheet (inspired by MoMA) – TestStyleSheet.

#import "CalendarDemoAppDelegate.h"

#import "TestStyleSheet.h"
#import "CalendarDemoViewController.h"

@implementation CalendarDemoAppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;

- (BOOL) application: (UIApplication *) application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions {
    [TTStyleSheet setGlobalStyleSheet: [[TestStyleSheet new] autorelease]];

    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.viewController = [[CalendarDemoViewController alloc] init];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

@end

Styling

Here’s default stylesheet for you to study:

#import "TestStyleSheet.h"

@implementation TestStyleSheet

- (TTStyle *) calendarCellStyle: (UIControlState) state {
    if (state & UIControlStateDisabled) {
        return [TTTextStyle styleWithColor: [UIColor clearColor] next: nil];
    }

    if (state & UIControlStateSelected) {
        return [TTSolidFillStyle styleWithColor: [UIColor grayColor] next:
                [TTTextStyle styleWithColor: [UIColor whiteColor] next: nil]];
    }

    return [TTTextStyle styleWithColor: [UIColor grayColor] next: nil];
}

- (TTStyle *) calendarMonthBarStyle {
    return
    [TTLinearGradientFillStyle styleWithColor1: RGBCOLOR(188, 200, 215)
                                        color2: RGBCOLOR(125, 150, 179) next:
     [TTFourBorderStyle styleWithTop: RGBCOLOR(213, 221, 230)
                               right: nil
                              bottom: RGBCOLOR(57, 70, 84)
                                left: nil
                               width: 1 next: nil]];

}

- (TTStyle *) calendarMonthBackButton: (UIControlState) state {
    return
    [TTTextStyle styleWithFont: [UIFont systemFontOfSize: [UIFont buttonFontSize]]
                         color: [UIColor whiteColor]
                   shadowColor: [UIColor grayColor]
                  shadowOffset: CGSizeMake(0, 1) next: nil];
}

- (TTStyle *) calendarMonthForwardButton: (UIControlState) state {
    return
    [TTTextStyle styleWithFont: [UIFont systemFontOfSize: [UIFont buttonFontSize]]
                         color: [UIColor whiteColor]
                   shadowColor: [UIColor grayColor]
                  shadowOffset: CGSizeMake(0, 1) next: nil];
}

- (TTStyle *) calendarMonthLabelStyle {
    return
    [TTTextStyle styleWithFont: [UIFont systemFontOfSize: [UIFont buttonFontSize]]
                         color: [UIColor whiteColor]
                   shadowColor: [UIColor grayColor]
                  shadowOffset: CGSizeMake(0, 1) next: nil];
}

- (TTStyle *) calendarGridViewStyle {
    return [TTSolidFillStyle styleWithColor: [UIColor whiteColor] next: nil];
}

@end

License

Code is distributed under MIT license, attribution is appreciated:

Copyright (C) 2011 by Componentix
http://www.componentix.com

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.

ios-calendar's People

Contributors

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