CalendarGUI Project (Completed!!)

Discussion in 'Mac Programming' started by zophtx, May 4, 2010.

  1. zophtx macrumors member

    Joined:
    Mar 8, 2010
    Location:
    Inside a Cocoa Book
    #1
    Code Been Posted!!!

    Sup i started on the second part of my Application for my Teacher. it is a Calendar. it going to be on a drawer and smaller than is is right now. like a the ical has, but different. it has a matrix of NSButtonCell 6r x 7c.

    the month will be labeled depending on the current month.
    (need help to set the current month to a integer value)

    the year will be 2010 for now and will be used as a integer turn to a string so i can use it as a label. when the current month = 12 and the current day = 31/30+1 than theYear++

    the size of of the cell is depended on the size of the image that is holding.(matrix has auto sizing cells)

    the current day will have the UsedSquare.png but right now i have when you click on a cell it will change but that is not i what is going to do.

    the code in the CalenderGUI File but not in the coloredButtons was made all by me so far. i read some references to classes.

    i need the help and support cause im stuck on some parts of this project so i listed couple of than so far

    tell what you think of what i have so far and what i can improve and work on.

    thanks in advance:p

    EDIT: Calendar Completed
     

    Attached Files:

  2. zophtx thread starter macrumors member

    Joined:
    Mar 8, 2010
    Location:
    Inside a Cocoa Book
  3. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #3
    You should probably use NSDateFormatter (-stringFromDate:, say) to get the month names; it will likely end up being simpler, and it will support places with other names for months. :)
     
  4. zophtx thread starter macrumors member

    Joined:
    Mar 8, 2010
    Location:
    Inside a Cocoa Book
  5. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #5
    This involves a bit of math and abstraction, but it is pretty straightforward. The first thing to remember about any calendar is that the vertical column (weekday) has a consistent pattern: if the number at the top is n, each successive number down the column is 7 higher than the one above it. Hence, it is easier (I would think) to go down the columns than go across the rows.

    You should study the class NSCalendar and its companion NSDateComponents. These will probably be the ones you will use to create a generic month layout. The difficult part will be figuring out how to set up the blank-square offsets at the top and bottom for when a month starts on a given day.

    Good luck
     
  6. zophtx thread starter macrumors member

    Joined:
    Mar 8, 2010
    Location:
    Inside a Cocoa Book
    #6
    i have been studying all the Cal/Date class that apple has read non stop and experimenting as well. but i keep on studying and im sure ill find a way.
    i could use the -dateSinceTimeInterval to set the next day. i ll keep experimenting an trying new things.

    also i have bee nstudy open source calender appliction like LRCalendarView class and SimpleCalendar see how they set the days up.
     
  7. zophtx thread starter macrumors member

    Joined:
    Mar 8, 2010
    Location:
    Inside a Cocoa Book
    #7
    I found Something!!!

    i found this code that display the all months and the days in the correct alignment of the month that the day are in. but it is in C and i need help getting it to work with the NSMatrix.

    code is here:
    Code:
    #include<stdio.h>
    
    #define TRUE    1
    #define FALSE   0
    
    int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    char *months[]=
    {
    	" ",
    	"\n\n\nJanuary",
    	"\n\n\nFebruary",
    	"\n\n\nMarch",
    	"\n\n\nApril",
    	"\n\n\nMay",
    	"\n\n\nJune",
    	"\n\n\nJuly",
    	"\n\n\nAugust",
    	"\n\n\nSeptember",
    	"\n\n\nOctober",
    	"\n\n\nNovember",
    	"\n\n\nDecember"
    };
    
    
    int inputyear(void)
    {
    	int year;
    	
    	printf("Please enter a year (example: 1999) : ");
    	scanf("%d", &year);
    	return year;
    }
    
    int determinedaycode(int year)
    {
    	int daycode;
    	int d1, d2, d3;
    	
    	d1 = (year - 1.)/ 4.0;
    	d2 = (year - 1.)/ 100.;
    	d3 = (year - 1.)/ 400.;
    	daycode = (year + d1 - d2 + d3) %7;
    	return daycode;
    }
    
    
    int determineleapyear(int year)
    {
    	if(year% 4 == FALSE && year%100 != FALSE || year%400 == FALSE)
    	{
    		days_in_month[2] = 29;
    		return TRUE;
    	}
    	else
    	{
    		days_in_month[2] = 28;
    		return FALSE;
    	}
    }
    
    void calendar(int year, int daycode)
    {
    	int month, day;
    	for ( month = 1; month <= 12; month++ )
    	{
    		printf("%s", months[month]);
    		printf("\n\nSun  Mon  Tue  Wed  Thu  Fri  Sat\n" );
    		
    		// Correct the position for the first date
    		for ( day = 1; day <= 1 + daycode * 5; day++ )
    		{
    			printf(" ");
    		}
    		
    		// Print all the dates for one month
    		for ( day = 1; day <= days_in_month[month]; day++ )
    		{
    			printf("%2d", day );
    			
    			// Is day before Sat? Else start next line Sun.
    			if ( ( day + daycode ) % 7 > 0 )
    				printf("   " );
    			else
    				printf("\n " );
    		}
    		// Set position for next month
    		daycode = ( daycode + days_in_month[month] ) % 7;
    	}
    }
    
    
    int main(void)
    {
    	int year, daycode, leapyear;
    	
    	year = inputyear();
    	daycode = determinedaycode(year);
    	determineleapyear(year);
    	calendar(year, daycode);
    	printf("\n");
    }
    i hope you can help me with the problem :)

    the month array i already have and the year setting i already have in OBJ-C all i need is to get the days fit in to the matrix:)
     
  8. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #8
    I have nothing to add right now on the code, other than to say that months can be spread over six weeks if they are 30 days or longer (all but February). That means a 5x7 grid is not sufficient unless you would double up a few days like some paper calendars do.

    -Lee
     
  9. zophtx thread starter macrumors member

    Joined:
    Mar 8, 2010
    Location:
    Inside a Cocoa Book
    #9
    ya i i fixed the how many cells are suppose to be in the matrix 6x7 grid is wat i have. i miscounted the rows in actally calendar when i first did this >)
     
  10. zophtx thread starter macrumors member

    Joined:
    Mar 8, 2010
    Location:
    Inside a Cocoa Book
    #10
    I Finished the Calendar

    i have posted the code for the calendar read the text file that comes with it.
    it still needs now work but it good enough to be called completed cause remember this is just a pice of the full application so i can do all the fixes after i get every thing altogether
     
  11. Bill McEnaney macrumors 6502

    Joined:
    Apr 29, 2010
    #11
    Can you include stdbool.h, so you won't need to define TRUE and FALSE?
     

Share This Page