• Stars
    star
    161
  • Rank 233,470 (Top 5 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 11 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Calendar View

iOS Calendar

Version License Platform CocoaPods CocoaPods

It's lightweight and simple control with supporting Locale and CalendarIdentifier. There're samples for iPhone and iPad, and also with using a popover.
alt tag alt tag
Using popover:

alt tag

How to install

Manual:

Add to your project the next source files:

CalendarView.h
CalendarView.m
NSDate+CalendarView.h
NSDate+CalendarView.m
NSString+CalendarView.h
NSString+CalendarView.m

CocoaPods:

pod 'Calendar-iOS'

How to use

You can add view in the Interface Builder and set class to CalendarView or create in the code:

CalendarView *calendarView = [[CalendarView alloc] initWithPosition:10.0 y:10.0];
[self.view addSubview:calendarView];

So, it's all, you should see the calendar view.
This component was created for iPhone/iPod resolution, for iPad its works, but it looks really small, if it's necessary, you can play with static constants in the CalendarView.m, and maybe in future, will be done the scaling.
This calendar has some modes:

typedef NS_ENUM(NSInteger, CalendarMode)
{
    CalendarModeDefault,
    CalendarModeMonthsAndYears,
    CalendarModeYears
};

Default - there're days, months and years, the user can change months with help swipe gesture or pinch gesture for transitions in the calendar
MonthsAndYears - available months and years
Years - only years

There are external methods to mimic the swiping behavior in case a different UI is desired. However, these events will be logged with a different event type than swiping.

There are also some options for display:

// Whether the currently selected date should be marked
@property (nonatomic, assign) BOOL shouldMarkSelectedDate;
// Whether today's date should be marked
@property (nonatomic, assign) BOOL shouldMarkToday;
// Whether the month and year headers should be shown
@property (nonatomic, assign) BOOL shouldShowHeaders;
// Preferred weekday start
- (void)setPreferredWeekStartIndex:(NSInteger)index;

Date Markers - Default behavior is to mark the currently selected date and not today, but this can be customized to suit your needs. If both are marked and coincide on the same day, it will show up with the current selection color, not today's color.
Headers - Default behavior is to show the headers, but they can also be hidden, in which case everything else will get shifted up accordingly (after a set needs display call).
Preferred Week Start - Default behavior behavior is Monday. Determines what day of the week is in the leftmost column.

How to use Locale and CalendarIdentifier

It's very simple and useful to create calendar base on your locale and of course your country.

NSLocale *persianLocale = [NSLocale alloc]initWithLocaleIdentifier:@"fa-IR"];
[self.calendarView setLocale:persianLocale];

And for using CalendarIdentifier use this property :

[self.calendarView setCalendarIdentifier:NSCalendarIdentifierPersian];

if you set useVeryShortWeekdaySymbols property to YES, use days of week name very short

self.calendarView.useVeryShortWeekdaySymbols = YES;

How to select range of date

English range selection Persian range selection If user Long press on items, can select date and for select end of range, Long press on end date. For get range date use didSelectRangeForStartDate:endDate delegate method like this :

- (void) didSelectRangeForStartDate:(NSDate *)startDate andEndDate:(NSDate *)endDate{ 
    NSLog(@"%s: start date :%@ \n end date : %@",__PRETTY_FUNCTION__,startDate,endDate); 
} 

How to handle changing date event

For this you should use CalendarViewDelegate protocol:

@interface ViewController : UIViewController <CalendarViewDelegate>

@end

And setup delegate:

self.calendarView.calendarDelegate = self;

After that you should implement required method didChangeCalendarDate:

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

For more details there're optional methods for other things:

@optional
- (void)didChangeCalendarDate:(NSDate *)date withType:(NSInteger)type withEvent:(NSInteger)event;
- (void)didDoubleTapCalendar:(NSDate *)date withType:(NSInteger)type;

How to customize colors

For customization of colors you can use the following properties:

// Main color of numbers
@property (nonatomic, strong) UIColor *fontColor;
// Color of the headers (Year and month)
@property (nonatomic, strong) UIColor *fontHeaderColor;
// Color of selected numbers
@property (nonatomic, strong) UIColor *fontSelectedColor;
// Color of selection
@property (nonatomic, strong) UIColor *selectionColor;
// Color of today
@property (nonatomic, strong) UIColor *todayColor;

For example:

self.calendarView.selectionColor = [UIColor colorWithRed:0.203 green:0.666 blue:0.862 alpha:1.000];
self.calendarView.fontHeaderColor = [UIColor colorWithRed:0.203 green:0.666 blue:0.862 alpha:1.000];

And you can see the result:
alt tag
It's free for using, feel free. And I hope it will be helpful.

License

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

More Repositories

1

Language-Manager-iOS

Language Manager iOS
Objective-C
233
star
2

Mac-OS-X-App-Menu-Bar-Popup

Mac OS X Application like a menu bar popup message
Swift
183
star
3

iOS-CoreMotion-Example

Core Motion in iOS using Swift
Swift
101
star
4

SwiftGoogleTranslate

Lightweight framework for using Cloud Translation API by Google
Swift
86
star
5

SwiftAssetsPickerController

A simple assets picker controller based on iOS 8 Photos framework. Supports iCloud photos and videos. It's written in Swift.
Swift
85
star
6

Swift-Amazon-S3-Uploading-Tutorial

How to upload a file to Amazon S3 using Swift
Swift
76
star
7

UICollectionViewHorizontalPaging

iOS UICollectionView Page Scrolling
Swift
71
star
8

iOS-Crosswords-Generator

A simple algorithm for generating crosswords written on Swift. Based on Python Crossword Puzzle Generator.
Swift
52
star
9

iOS-Shared-CoreData-Storage-for-App-Groups

iOS Shared CoreData Storage for App Groups
Swift
49
star
10

SwiftHUEColorPicker

iOS HUE color picker
Swift
46
star
11

iOS-Swift-Drawing-App

Swift Drawing Application Sample
Swift
40
star
12

iOS-AirDrop-Custom-Data

iOS Airdrop Custom Data Transferring Example
Objective-C
38
star
13

CheckMarkView

UI view which draws programmatically a checkmark with different styles
Swift
35
star
14

iOS-Swift-In-App-Purchases-Sample

iOS Swift In-App-Purchases Sample
Swift
33
star
15

SKTextureGradient

A SpriteKit SKTexture Gradient
Swift
29
star
16

iOS-MapKit-Tutorial

iOS MapKit Getting Started
Swift
26
star
17

iOS-MySQL-Client

iOS MySQL client
Objective-C
26
star
18

iOS-Today-Extension-Simple-Tutorial

iOS Today Extension Simple Tutorial
Swift
25
star
19

Quizlet-iOS

iOS framework for using Quizlet API 2.0
Objective-C
18
star
20

UIAlertController-Customization

Customization of UIAlertController
Swift
18
star
21

JobsFinder

A script which parses Upwork RSS feed and sends notifications to Telegram
JavaScript
17
star
22

SwiftlySlider

A simple iOS slider control
Swift
14
star
23

iOS-Heart-Rate-Monitor

iOS Heart Rate Monitor
Objective-C
12
star
24

SignalStrengthIndicator

Signal Strength Indicator
Swift
11
star
25

iOS-Dragon-Mobile-SDK-Example

Nuance Dragon Mobile SDK and ObjectAL
HTML
10
star
26

MBFileDownloader

A file downloader.
Objective-C
9
star
27

The-Pursuit-Demo

3D racing with physics powered by Marmalade SDK and Bullet Physics
GLSL
9
star
28

iOS-UIImage-render-to-PDF

iOS Render UIImage to PDF and merging PDF files
Objective-C
9
star
29

iOS-Pie-Chart

iOS Pie Chart
Objective-C
9
star
30

SwiftlyScrollSlider

A custom scroll slider for UIScrollView
Swift
8
star
31

3D-Touch-Quick-Actions-Demo

iOS 3D Touch: How to add quick actions
Swift
8
star
32

iOS-YouTube-Browser

iOS YouTube Browser Sample
Objective-C
8
star
33

iOS-Swift-ObjC-Mix

An example of the mixing Swift and Obj C code in the same project
Objective-C
7
star
34

SwiftThicknessPicker

iOS thickness picker
Swift
6
star
35

iOS-Document-Iteraction

iOS: How to copy epub files from your app to iBooks app
Swift
6
star
36

iOS-Tag-List

iOS Tag List
Objective-C
6
star
37

SwiftTintedButtonExtension

A small Swift extension for tinting UIButton, like a UIBarButtonItem or a UINavigationItem
Swift
5
star
38

iOS-QuickBlox-File-Uploader-Downloader

Quickblox: Uploading from a file, downloading to a file
Objective-C
4
star
39

UIStripedView

A striped view
Objective-C
3
star
40

WaitSpinner

Very very simple activity indicator
Objective-C
3
star
41

iOS-Frequency-Table

iOS Frequency Table
Objective-C
3
star
42

UITextViewPlaceholder

UITextView Placeholder Tutorial
Swift
3
star
43

UISegmentedControl_IconAndText

A simple category for adding icon and text together to default UISegmentedControl
Objective-C
3
star
44

UIColorRGBA

Provides a convenience UIColor method for set up a color from a HEX string in Swift.
Swift
2
star
45

SwiftyAccountKit

Facebook AccountKit wrapper
Swift
2
star
46

T-Block

T-Block
C++
1
star
47

SwiftOxfordAPI

A framework to use Oxford Dictionaries API written in Swift
Swift
1
star
48

Patchcord

The project represents an example of Redux architecture using SwiftUI + Combine + CoreData.
Swift
1
star
49

Locale-Alphabet

An example that shows how to take the current alphabet from the text
Objective-C
1
star
50

SwiftUI-WidgetKit-Gradient-Issue

This code shows a bug with gradient colors which is happening using Widgets extension for iOS 14
Swift
1
star
51

CIColorRGBA

Provides a convenience CIColor method for set up a color from a HEX string in Swift
Swift
1
star