MonoTouch Calendar control is here!
By ESCOZ posted January 22nd, 2010
Here’s a new MonoTouch UIView many people will probably find useful: CalendarMonthView. As you can see in the picture on the side, this control is a copy of the built in Month View calendar control, used in Apple’s calendar app. This includes animations when moving between months, highlighting of the cells being selected and current day, etc.
Even if you’re not going to use the control anytime soon, I would still recommend taking a look at the code simply an example of how to develop a control like it. This code is based on the calendar control from the great Tapku Library, created by Devin Ross, and reading over that was a great way of learning more about the UIKit.
Using this control is really simple, as you can see in theĀ sample CalendarMonthViewController. All you have to do is instantiate a new CalendarMonthView control, and add it as a subview to the current view:
public class CalendarMonthViewController : UIViewController
{
public CalendarMonthView MonthView;
public override void ViewDidLoad()
{
MonthView = new CalendarMonthView();
MonthView.OnDateSelected += (date) => {
Console.WriteLine(String.Format("Selected {0}", date.ToShortDateString()));
};
MonthView.OnFinishedDateSelection += (date) => {
Console.WriteLine(String.Format("Finished selecting {0}", date.ToShortDateString()));
};
MonthView.IsDayMarkedDelegate += (date) => {
return (date.Day % 2==0) ? true : false;
};
View.AddSubview(MonthView);
}
}
During the next few days, I’ll be adding a few new features to the control, like Range selection, more events, etc. The code still have a few small rendering bugs, which I’m working on. If there’s anything you would like to see implemented, let me know!
The full source code can be downloaded from my samples library in GitHub.
Update: I just committed a couple of changes to the control, one of them being the new delegate IsDateMarkedDelegate, which is used to display a mark for a day in the grid. To use this, simply create a new delegate or lambda expression (as above), and return true to display the mark. This to me seems considerably easier to implement then passing a list of DateTime objects that should have the dates, which is how this is implemented in the Tapku control.
Filed under: Development | Tags: MonoTouch, Redpoint | 12 Comments »
MonoTouch Calendar control is here!…
Thank you for submitting this entry – Trackback from MonoTouch.Info…
Hello,
Could MonoTouch be used in apps sold in the app store. Is it making private api calls.
I would like to use you ‘revised’ calendar, if possible.
Thank you
Hi RM,
Yeah, there are quite a few monotouch apps in the store already! It doesn’t make any private calls, because the MonoTouch API is based on Apple’s SDK.
Feel free to use the calendar, all the code is free on github. The calendar works well on the iPhone 3GS, but on the 3G the animations are a little slow. I’ll be making changes to the code soon to fix that.
Thanks for the wonderful control
I just faced a problem today. In a month if there are 6 weeks like May 2010, the last row click event is not firing. Not sure if I am doing anything wrong.
Please help
Thanks
Hi Xeta,
I fixed that bug a few weeks ago.. Are you using the latest version of the code on github?
Just wanted to drop a note about how much appreciated your tools are!
Thanks Ian!
Thanks Ian for the great control! However there is a bug in it when checking IsDayMarked… for the last and next month you use the current year and month, instead of subtracting/adding one month to the viewDay DateTime. Just so you know
Just found another related bug: the day passed into new DateTime(…) for viewDay is also wrong for the previous/next month – has to be lead and dayCounter, respectively…
Hi Olaf,
I fixed those bugs a few weeks/months ago, have you looked at the code recently?
Can you send me a test case that I can try? How exactly can I reproduce the issue? I’ll be adding a few more things to this control this week, and would love to get any feedback possible.
Thanks!
This is friggin’ awesome! Thanks so much!
I used the code and with some individual changes it works great.
Thanks for your effort.