Git Product home page Git Product logo

khmomtechs / fscalendar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from husseinhj/fscalendar

0.0 2.0 0.0 5.18 MB

Gregorian, Persian and Islamic calendar for iOS, This is the fork version of FSCalendar. A fully customizable iOS calendar library, compatible with Objective-C and Swift

Home Page: https://husseinhj.github.io/FSCalendar/

License: MIT License

Objective-C 87.37% Swift 12.17% Ruby 0.46%

fscalendar's Introduction

logo
Build Status Version

Platform Carthage compatible
Languages

Table of contents

Screenshots

Persian Calendar and Arabic Calendar

Week Month DIY
Range Week range Range selection

iPhone

fscalendar

iPad

fscalendar-ipad

Safe Orientation

fscalendar-scope-orientation-autolayout

Today Extension

iOS8/9 iOS10
today1 today2

Interactive Scope Gesture

1

DIY support

1

To customize your own cell, view DIY Example in Example-Swift or Example-Objc

Swipe-To-Choose

Single-Selection
Swipe-To-Choose
Multiple-Selection
Swipe-To-Choose
DIY
Swipe-To-Choose
1 2 3

Achievement of Users

| 1 | 2 | 3 | 4
| | ------------- | ------------- | ------------- | ------------- |

Installation

CocoaPods of RTL support Version:

  • For iOS8+: 👍
use_frameworks!
target '<Your Target Name>' do
    pod 'FSCalendar+Persian'
end
  • For iOS7+:
target '<Your Target Name>' do
	pod 'FSCalendar+Persian'
end

NSCalendarExtension is required to get iOS7 compatibility.

Carthage:

  • For iOS8+
github "hussein_hj/FSCalendar"

Manually:

  • Drag all files under FSCalendar folder into your project. 👍

Alternatively to give it a test run, simply press command+u in Example-Objc or Example-Swift and launch the UITest Target.
Only the methods marked "👍" support IBInspectable / IBDesignable feature. Have fun with Interface builder

Setup

Use Interface Builder

1、 Drag an UIView object to ViewController Scene 2、 Change the Custom Class to FSCalendar
3、 Link dataSource and delegate to the ViewController

fscalendar-ib

4、 Finally, implement FSCalendarDataSource and FSCalendarDelegate in your ViewController

Or use code

@property (weak , nonatomic) FSCalendar *calendar;
// In loadView(Recommended) or viewDidLoad
FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
calendar.dataSource = self;
calendar.delegate = self;
[self.view addSubview:calendar];
self.calendar = calendar;

Or swift

fileprivate weak var calendar: FSCalendar!
// In loadView or viewDidLoad
let calendar = FSCalendar(frame: CGRect(x: 0, y: 0, width: 320, height: 300))
calendar.dataSource = self
calendar.delegate = self
view.addSubview(calendar)
self.calendar = calendar

To use FSCalendar in Swift3, see Example-Swift for details.

How to use RTL calendar?

It's easy (Objective-C) :

calendar.locale = [NSLocale localeWithLocaleIdentifier:@"fa-IR"];
calendar.identifier = NSCalendarIdentifierPersian;
calendar.firstWeekday = 7;

....

#pragma mark - FSCalendarDataSource

- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar {
    return [self.dateFormatter dateFromString:@"2016-07-08"];
}

Swift :

calendar.locale = NSLocale.init(localeIdentifier: "fa-IR") as Locale
calendar.identifier = NSCalendar.Identifier.persian.rawValue
calendar.firstWeekday = 7

....

// MARK:- FSCalendarDataSource
    
func minimumDate(for calendar: FSCalendar) -> Date {
    return self.formatter.date(from: "2016-07-08")!
}

Also can see here where is these codes

Warning

FSCalendar doesn't update frame by itself, Please implement

  • For AutoLayout
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
    self.calendarHeightConstraint.constant = CGRectGetHeight(bounds);
    // Do other updates here
    [self.view layoutIfNeeded];
}
  • For Manual Layout
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
    calendar.frame = (CGRect){calendar.frame.origin,bounds.size};
    // Do other updates here
}
  • If you are using Masonry
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
    [calendar mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(bounds.size.height));
        // Do other updates
    }];
    [self.view layoutIfNeeded];
}
  • If you are using SnapKit
func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) {
    calendar.snp.updateConstraints { (make) in
        make.height.equalTo(bounds.height)
        // Do other updates
    }
    self.view.layoutIfNeeded()
}

Roll with Interface Builder

fscalendar - ibdesignable

Pre-knowledge

In Swift3, NSDate and NSDateFormatter have been renamed to Date and DateFormatter , see Example-Swift for details.

How to create NSDate object

  • By NSCalendar.
self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];

Then:

NSDate *date = [gregorian dateWithEra:1 year:2016 month:9 day:10 hour:0 minute:0 second:0 nanosecond:0];
// 2016-09-10 00:00:00
  • Or by NSDateFormatter
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateFormat = @"yyyy-MM-dd";

Then:

NSDate *date = [self.formatter dateFromString:@"2016-09-10"];

How to print out NSDate object

  • Use NSDateFormatter
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateFormat = @"yyyy/MM/dd";
NSString *string = [self.formatter stringFromDate:date];
NSLog(@"Date is %@", string);

How to manipulate NSDate with NSCalendar

self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
  • Get component of NSDate
NSInteger era = [self.gregorian component:NSCalendarUnitEra fromDate:date];
NSInteger year = [self.gregorian component:NSCalendarUnitYear fromDate:date];
NSInteger month = [self.gregorian component:NSCalendarUnitMonth fromDate:date];
NSInteger day = [self.gregorian component:NSCalendarUnitDay fromDate:date];
NSInteger hour = [self.gregorian component:NSCalendarUnitHour fromDate:date];
NSInteger minute = [self.gregorian component:NSCalendarUnitMinute fromDate:date];
...
  • Get next month
NSDate *nextMonth = [self.gregorain dateByAddingUnit:NSCalendarUnitMonth value:1 toDate:date options:0];
  • Get next day
NSDate *nextDay = [self.gregorain dateByAddingUnit:NSCalendarUnitDay value:1 toDate:date options:0];
  • Is date in today/tomorrow/yesterday/weekend
BOOL isToday = [self.gregorian isDateInToday:date];
BOOL isYesterday = [self.gregorian isDateInYesterday:date];
BOOL isTomorrow = [self.gregorian isDateInTomorrow:date];
BOOL isWeekend = [self.gregorian isDateInWeekend:date];
  • Compare two dates
BOOL sameDay = [self.gregorian isDate:date1 inSameDayAsDate:date2];
// Yes if the date1 and date2 are in same day


[self.gregorian compareDate:date1 toDate:date2 toUnitGranularity:unit];
// compare the era/year/month/day/hour/minute .etc ...
// return NSOrderAscending/NSOrderSame/NSOrderDecending

BOOL inSameUnit = [self.gregorian isDate:date1 equalToDate:date2 toUnitGranularity:unit];
// if the given unit (era/year/month/day/hour/minute .etc) are the same

Contact

If your made a beautiful calendar with this library in your app, please take a screen shot and @me in twitter. Your help really means a lot to me!

License

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

fscalendar's People

Contributors

wenchaod avatar husseinhj avatar gemmakbarlow avatar sochalewski avatar vendruscolo avatar roark31337 avatar mastohhh avatar kallahir avatar jklp avatar lucianocn avatar readmecritic avatar schaechtele avatar yas375 avatar zjmdp avatar

Watchers

 avatar James Cloos 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.