Skip to content

squimer/JTCalendar

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A fork from JTCalendar

JTCalendar is a calendar control for iOS easily customizable.

What's new?

  • monthDidChange method added to delegate.
  • Swift examples.

Screenshots

Month

Usage

Swift Warning

If you're using swift, you'll need a bridging header file (You can create one following this tutorial).

Once you have a YouAppName-Bridging-Header.h file, add the following lines:

#import "JTCalendar.h"
#import "JTCalendarMenuView.h"
#import "JTCalendarContentView.h"

And you ready to go.

Basic usage

You have to create two views in your UIViewController.

The first view is JTCalendarMenuView, it represents the months.

The second view is JTCalendarContentView, the calendar itself.

Your UIViewController must implement JTCalendarDataSource

Objective-C

#import <UIKit/UIKit.h>

#import "JTCalendar.h"

@interface ViewController : UIViewController<JTCalendarDataSource>

@property (weak, nonatomic) IBOutlet JTCalendarMenuView *calendarMenuView;
@property (weak, nonatomic) IBOutlet JTCalendarContentView *calendarContentView;

@property (strong, nonatomic) JTCalendar *calendar;

@end

JTCalendar is used to coordinate calendarMenuView and calendarContentView.

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
        
    self.calendar = [JTCalendar new];
    
    [self.calendar setMenuMonthsView:self.calendarMenuView];
    [self.calendar setContentView:self.calendarContentView];
    [self.calendar setDataSource:self];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    [self.calendar reloadData]; // Must be call in viewDidAppear
}

- (BOOL)calendarHaveEvent:(JTCalendar *)calendar date:(NSDate *)date
{
    return NO;
}

- (void)calendarDidDateSelected:(JTCalendar *)calendar date:(NSDate *)date
{
    NSLog(@"%@", date);
}

- (void)calendarDidChangeMonth:(JTCalendar *)calendar date:(NSDate *)date
{
    NSLog(@"Date: %@", date);
}

@end

Swift

JTCalendar is used to coordinate calendarMenuView and calendarContentView.

import UIKit

class ViewController: UIViewController, JTCalendarDataSource {
    
    @IBOutlet weak var calendarMenuView: JTCalendarMenuView!
    @IBOutlet weak var calendarContentView: JTCalendarContentView!
    
    var calendar: JTCalendar!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.calendar = JTCalendar()
        
        self.calendar.menuMonthsView = calendarMenuView
        self.calendar.contentView = calendarContentView
        self.calendar.dataSource = self
    }

    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        self.calendar.reloadData()
    }
    
    func calendarHaveEvent(calendar: JTCalendar!, date: NSDate!) -> Bool {
        return true
    }
    
    func calendarDidDateSelected(calendar: JTCalendar!, date: NSDate!) {
        println(date)
    }
    
    func calendarDidChangeMonth(calendar: JTCalendar!, date: NSDate!) {
        println(date)
    }
    
}

Customize the design

You have a lot of options available for personnalize the design. Check the JTCalendarAppearance.h file for see all options.

Objective-c:
self.calendar.calendarAppearance.calendar.firstWeekday = 2; // Monday
self.calendar.calendarAppearance.ratioContentMenu = 1.;
self.calendar.calendarAppearance.menuMonthTextColor = [UIColor whiteColor];
self.calendar.calendarAppearance.dayCircleColorSelected = [UIColor blueColor];
self.calendar.calendarAppearance.dayTextColorSelected = [UIColor whiteColor];
[self.calendar reloadAppearance];
Swift:
self.calendar.calendarAppearance.calendar().firstWeekday = 2
self.calendar.calendarAppearance.ratioContentMenu = 1
self.calendar.calendarAppearance.menuMonthTextColor = UIColor.whiteColor()
self.calendar.calendarAppearance.dayCircleColorSelected = UIColor.blueColor()
self.calendar.calendarAppearance.dayTextColorSelected = UIColor.whiteColor()
self.calendar.reloadAppearance()

Recommendation

You may want to open your calendar on a specific date.

Objective-c:
[self.calendar setCurrentDate:myDate];
Swift:
self.calendar.currentDate = myDate

Original Author

License

JTCalendar is released under the MIT license. See the LICENSE file for more info.

About

A customizable calendar view for iOS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 98.6%
  • Ruby 1.4%