• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

vgrichina/ios-calendar: Stylable and extensible month calendar view for iPhone

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

vgrichina/ios-calendar

开源软件地址:

https://github.com/vgrichina/ios-calendar

开源编程语言:

Objective-C 98.0%

开源软件介绍:

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.



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap