slytrkmn
slytrkmn

Reputation: 272

How can i select dates programmatically and show on FSCalendar

I used FSCalendar(https://github.com/WenchaoD/FSCalendar) in my project. If user click repeat button, the events repeats everyday. I want to show it on calendar which is in my application. How can I do it?

Upvotes: 2

Views: 12995

Answers (3)

Hardik
Hardik

Reputation: 399

If you want to select date then below method will be helpful, where calendar is outlet of FSCalendar.

calendar.select(calendar.today)

And if you want to select multiple dates then the best way would be to use event dots, and that can be possible through below delegate method of FSCalendar Data source,

func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int { //number of dots you want to show }

or if you really want to show dates selected, you can use below method smartly and returning different colours for dates that you want to select,

    public func calendar(_ calendar: FSCalendar, appearance: FSCalendarAppearance, fillDefaultColorFor date: Date) -> UIColor?
{
    if your date
    {
         //return the colour for your dates
    }
    else
    {
         //return default colour
    }
}

Hope, this answer helps you.

Upvotes: 7

Mauricio Chirino
Mauricio Chirino

Reputation: 1232

I don't know how you're persisting that information (the scheduled date), what i can tell you is that you can easily add a dot (or more if you'd like, just change the number) with the following delegate:

`func calendar(calendar: FSCalendar, numberOfEventsForDate date: NSDate) -> Int {
    let formatter = NSDateFormatter()
    formatter.dateFormat = "MM-DD"
    let date1 = formatter.stringFromDate(yourDate)
    let date2 = formatter.stringFromDate(date)
    return date1 == date2 ? 1 : 0
}`

This method is one of FSCalendar delegates and it iterates all days in the current month (each one of them represented in date variable). In the example above i'm comparing if the any given date is equal to yourDate variable which has to be a NSDate as well by transforming both of them into Strings via NSDateFormatter in Month-Day format so the comparison is equal for all months. If true, return 1 (this indicates 1 dot, you may change it for more if you want to), otherwise return 0 dots below the specific date.

This code is Swift 2.3 compliance.

Upvotes: 0

Surjeet Rajput
Surjeet Rajput

Reputation: 1301

For Remainder app you need to do or use following thing.

1.Realm or Core Data - for Data persistency.

2.local notification - to notify user that some event is occured. you need to use UILocalNotification that have one property fireDate property.

Upvotes: 0

Related Questions