Giter Site home page Giter Site logo

wenchaod / fscalendar Goto Github PK

View Code? Open in Web Editor NEW
10.5K 213.0 1.9K 2.45 MB

A fully customizable iOS calendar library, compatible with Objective-C and Swift

License: MIT License

Objective-C 87.96% Ruby 0.20% Swift 11.84%
swift objective-c calendar library cocoapods carthage ios

fscalendar's Introduction

logo

Apps Using Total Downloads
Travis Version Platform Carthage compatible SwiftPM
Languages

Table of contents

Screenshots

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:

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

NSCalendarExtension is required to get iOS7 compatibility.

Carthage:

  • For iOS8+
github "WenchaoD/FSCalendar"

SPM:

Add dependency:

.package(url: "https://github.com/WenchaoD/FSCalendar.git", from: "2.8.4")

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.

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

Support this repo


* Support with  
* Support with or

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

ageevvalentin avatar gemmakbarlow avatar githubgaoyang avatar gsbernstein avatar jameskuang avatar jklp avatar kallahir avatar lucianocn avatar mastohhh avatar readmecritic avatar roark31337 avatar sakshibala-halodoc avatar schaechtele avatar sochalewski avatar sookim-1 avatar taehyeon-kim avatar techinpark avatar tomaskraina avatar tywhang avatar vendruscolo avatar wenchaod avatar wlxo0401 avatar yas375 avatar zbencz3 avatar zjmdp avatar zntfdr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fscalendar's Issues

Build failed!

Build failed with this error:
ld: library not found for -lPods-FSCalendar-FSCalendar

FSCalendar Improvements

Hey @f33chobits,

First of all thank you for FSCalendar it certainly is a nice tool for iOS. Here I suggest a couple of improvements for it:

· FSCalendar should let select multiple dates by the user (with more than one circle).
· FSCalendar should programmatically let add circles to the desired dates(for instance from a [NSDate]).

Thank you again for the effort you have put in it!

selectedDate

Hi,

It would have been really better if we were able to set the selectedDate which is now readonly. On the other hand, the currentDate is not that useful to be settable. Can you help me figure out how to swap them? or give the make selectedData writable?

日历怎么打多个点?

日历怎么打多个点?有提供接口么?或者返回一个View,或者给某天加特定的颜色、背景等等

No response for date selection

Hi @f33chobits , I met a problem here.

I used your control in a xib IB file , the setting was showing in the below screenshots:
image
image

And I implemented the protocol:
image

When I was running the simulator, there was no print information if I selected a date. Do you have any ideas?

Using the delegate and datasource methods in Swift

How can I use the methods if my project is Swift based?

func didSelectDate(calendar:FSCalendar,date:NSDate)
{
    print(date)
}
/*
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date
{
// Do something
}*/

I tried the above, but it does not get triggered..

Header customisation

@f33chobits First of all thanks for creating this lib. I found FSCalendar very helpful with my recent project. I was just wondering if you're planning to add more customisation options to the header view appearance? ( e.g. background colour, custom previous/next month views/actions )

Choice of date occurs only when you long press

Hi!
Thank you for an excellent calendar control.
I noticed an intersting bug: while pressing the number of the calendar - the choise does't work, but if you hold down and release (long press) - the date is selected correctly.
What do you think what may be related to this problem?

Week view and header customization

Hello,

In my project I need a calendar and your lib seems to fit my needs, expect that I need to be able to have a week mode view of the calendar. This feature exists already in this libs see also demo GIF.

Also I want to know if it's possible to customize the header of the calendar to be like this :

https://s3.amazonaws.com/cocoacontrols_production/uploads/control_image/image/5242/screenshot.PNG

and the text color of the days ?

https://github.com/jonathantribouharet/JTCalendar

Demo :
https://github.com/jonathantribouharet/JTCalendar/blob/master/Screens/example.gif

Incorrect date sent to calendarView subtitleForDate:(NSDate *)date

Looks like the date being sent to "SubtitleForDate" is incorrect. I simply echoed back the day being sent to the method which should make the subtitle the same as the day - but as you can see from the example, the subtitle doesn't match.

  • (NSString *)calendar:(FSCalendar *)calendarView subtitleForDate:(NSDate *)date

    {

    return [date fs_stringWithFormat:@"dd"];

    }

fscalendar

When minimumDateForCalendar is set, I am seeing Two Months in title

Hi when I implemented minimumDateForCalendar, initially i can see two month names in title. And when I swipe right, everything back to normal.

Attaching the screenshot
img_0001

It would also help if minimumDateForCalendar is set, it should disable all the dates before the minimum date.

Currently I am handling it in shouldSelectDate implementation. But when I do that, If I select dates of next month (which are visible in existing month in light gray color), they some different date in the same column gets selected.

Two months shown on vertical flow

I am having the same problem on version 0.9.3 on Issue #37 but changing the minimum date does not fix it. When I switch the flow to Horizontal I don't have this problem, only when on Vertical.

screen shot 2015-08-17 at 2 24 36 pm

Since you mentioned this could be related to the minimum date, I have removed the minimum date callback and now the problems are even more bizarre. The month headers now say the year 2061. However, when I select the date, it's still the correct month in 2015.

screen shot 2015-08-17 at 2 53 42 pm

I should mention I am using Xcode Beta 5 and compiling with the iOS 9 SDK. Appreciate any help you can provide on this. Thanks!

flicketing while reloading

Hi again,

There is a flickering of the dates collection view to while reloading which obvious. Is it normal or I'm not doing good in datasource. I see the dots fot events show up in other dates for small fraction of time and disappear.

Minimum / Maximum date properties / swipeable menu bar / warnings

Hi,

I had a look at your example the other day and completely missed that you have to swipe on the calendar body to get the month to change in horizontal mode. Looking again today, I noticed that you can swipe, but you can't swipe on the month. :(

I really think this an unintuitive experience, please can to make a fix this?
It seems such a shame that this is missing!

Also, scanning through the source, I notice there are private minimum and maximum date variables, it would be awesome if these could be made public, so a date range could be added.

Also, another thing which concerns me, when running the iOS 8 and iphone 6, there's a tonne of warnings and depreciations. I know these could be hidden with a flag in the podfile, but most of these seem very simple to fix, xcode even provides the answers to the them.

I just wanted to provide some feedback and give you a pat on the back, good job.

Thoughts ?

Best regards,

Jules.

Library not found

When i try to run the example project, I get this error:

ld: library not found for -lPods-FSCalendar-FSCalendar

So, i check my build phases and found that libPods-FSCalendar.a is not there. Where can I get this library?

Specific Time in FSCalendar

Hello, first of all congratulations for your work I have been very helpful and forgive my bad English, I write from Italy :)
I wanted to ask you a favor ... I have a problem ... I'm using your calendar to issue a local notification on my iPhone, the problem is that the notification is issued properly on the selected day but at 00:00 I would need that notification is set to a specific time of my choice, I can not find the right spot in your code to be able to get this ...

In short, the local notification should be out at 9:00 of the selected day on your calendar ... you can help me with this ??

thanks Fabio

Calendar scrolling to wrong month

Here's how to reproduce.

  1. Run example program.
  2. Switch to vertical.
  3. Scroll to March 2015.
  4. Using settings screen, select April 3rd.
  5. Tap on March 31st.

At this time the calendar will move to May instead of March.

Week start day

Hello,
first of all sorry for my bad english :P

could be great to have the possibility to set the week start day of the calendar.
I like so much this calendar and the way it's developed, very clean, but without this parameter i can't use it :(

I have added on my version a little function that may be useful, it just move the calendar to the choosed month:

- (void)moveToMonth:(NSDate*)todate {
    NSInteger scrollOffset = [todate fs_monthsFrom:[NSDate dateWithTimeIntervalSince1970:0]];
    scrollOffset++;

    CGPoint destOffset;

    if (self.flow == FSCalendarFlowHorizontal) {
         destOffset = CGPointMake(_collectionView.fs_width*scrollOffset, 0);
    } else if (self.flow == FSCalendarFlowVertical) {
        destOffset = CGPointMake(0, _collectionView.fs_height*scrollOffset);
    }

    [_collectionView setContentOffset:destOffset animated:YES];

    if (_header) {
        _header.scrollOffset = scrollOffset;
    }
}

iPad Enhancement

I'm working on implementing a calendar and really like this library. I was wondering if there is a possibility to increase the height of the scrollView and weekday cell heights to make for easier use on the iPad?

I've attached what it currently looks like and an example of making it larger. Not sure what the right dimensions would be, but was wondering if we could open it up for discussion.

ios simulator screen shot mar 4 2015 9 19 39 pm
ios simulator screen shot mar 4 2015 9 20 14 pm

Calendar scrolling to wrong month

How to reproduce :

  1. Start example app
  2. Switch to vertical mode
  3. tap on top screen

Then calendar will move to start date (1970 in my case)

Need some customization with the control

Hello there, you've made a good component! Thank you so much. I want to use it in my app, but before adopting I would like to know whether this can be possible or not? Please check attached screenshot. Also, if its not possible by a properly suggest me a way and I'll handle by my self. But if its possible by just setting up a property would be great enough for me.

ios simulator screen shot 26-jun-2015 6 29 33 pm

(º–º)

Conflict with shouldSelectDate delegate call on future month

First of all let me say I love this control. Very well done. Best I've seen of the dozens of calendar controls out there.

I have implemented the calendar:shouldSelectDate delegate callback to prevent the user from selecting a date before today. The issue I'm having is that when the user selects one of placeholder cells for the next month, the delegate callback is not passing in the correct date.

So, for example, given the month of June 2015, if the user selects the placeholder cell for July 1, I would expect the calendar to animate to the new month. However, what is happening is the wrong date is being sent to the delegate callback (it's actually sending June 3) which then causes my callback to return NO and the calendar never animates to the new month.

I'm hoping I'm being clear. Let me know if you have any questions. Thanks again!

Help me!

I don't set color for status date disable?

Can selected Cell be clear after scroll to next month

  1. Select a cell, it doesn't render the blue selected color
  2. Scroll to next month, then scroll back, the cell is rendered with blue color

This seems a little strange, shouldn't it behave like this

  1. Select a cell, it will render with the blue color
  2. Scroll to next month, then scroll back, the cell is rendered with normal color

Crash bug

when setting the initial calendar flow direction in viewDidLoad resulted in crash.
_calendar.flow = FSCalendarFlowVertical;

Current date issue

Great calendar! Thanks for sharing. There seems to be a bug where the default month is 1 month earlier. You can see this in the demo as well it loads Feb instead of March (current month) and when selecting the date under the settings it goes to wrong month as well.

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.