Tuesday, January 19, 2010

[tutorial]How to use iPhone calendar control

iPhone calendar control is an open source class library, it can help you insert a calendar in your iPhone software. Use it is very easy.

Download code

If you know how to install svn, or your computer already installed svn, you can just use svn download codes:

svn checkout http://iphonecal.googlecode.com/svn/trunk/ iphonecal-read-only

or, you can down codes from this two links:
http://iphonecal.googlecode.com/svn/trunk/TdCalendarView.h
http://iphonecal.googlecode.com/svn/trunk/TdCalendarView.m

Create a iPhone application project

Once you downed codes, you need create an iPhone application project. Open Xcode, click "File"->"New Project..." Menu, with the opened dialog, select View-based Application.


Name you project as TestiPhoneCal (or other anything.).



After you create project, click "Project"->"Add to project...", select downloaded files, keep "Copy items into destination group's folder" selected.








Setup view class

Open your nib file.


select which view that you need as calendar, set it's class as TdCalendarView.


Ok, run your program, you will see your calendar.



If you have trouble follow this tutorial, you can use my demo project as your start & code template. Download url is http://iphonecal.googlecode.com/files/TestiPhoneCal.zip .

Chinese Version/中文版

13 评论:

Kiran Thorat said...
This comment has been removed by the author.
tiny said...

Can you mail your code to me?

I will review it for you.

My email: tinyfool@gmail.com

Troy said...

Love what you did with this class.

I am wondering though. How do you set the day flags?

I have added this class to a flip view. One side is your calendar and the other is my data. Once I set data for a specific date I want to reflect those changes on the calendar.

tiny said...

TdCalendarView have a method "setDayFlag", you can use it.

Néstor said...

how i setup the sunday as first day of week? good, not only show sunday as first day of week, also show the correct date?

tiny said...

sorry, Néstor.

Now, only way is you self modify the code, sorry.

terrykwoktk said...

i'm not sure about the sebtence of "set it's class as TdCalendarView. " does it means we have to change the name of the original xib file(says, the calendarViewController.xib -> tdCalendar View, dooen't it?

but i got a blank view on the simulator.

conorhigginsmaxmsp said...

Hi,

thanks for this component, it seems like it could be very useful for my current project. How easy is it to customize the calendar though? Can you change the colours and width etc?

Thanks in advance,
Conor

Vidyabhushan said...

Thanks for the tutorial, very useful, Can you please mail me the code. thanks a lot.

Ron said...

Thanks for the sample code. I was just asked at to create a calendar page and I did nit know that iPhone SDK did not have built in framework.
Just need to add another string in each cell. Excellent Job!

Ron said...

I am a newbie in this iPhone world, so if this is impossible, please let me know. Can you give me snippet of code or point me in the direction of a solution. I need to be able to click on a date, then present a UITableView that will display a list of actives for that date.

Bob said...

Nice code. I am using in an iPad app that I am building. Can you tell me how to highlight the date that has been previously selected? I select the date, when I return to the control, I would like to see that date shown and highlighted just as it is shown when selected. Thanks!

madocspace said...

Thanks for the calendar, i have only a nooby, so here it comes my question, how can i change the numerical format of the month to, for instance, march and so on?

i think i have to look into this line:
NSString *title_Month = [[NSString alloc] initWithFormat:@"%d - %d",currentMonthDate.month,currentMonthDate.year];