-1

I want to create a custom calendar application using an array of buttons,so I want to know how to start with this..please help me out.w.r.t this,I want to know if any libraries are present which uses buttons and not a grid layout,because I dont want to use a grid layout

Hello friends,I tried to solve this issue with comments below and wrote this code

for (int columnIndex = 0; columnIndex < 6; columnIndex++) 
    {

        // now loop over the rows
        for (int rowIndex = 0; rowIndex < 7; rowIndex++)
        {   

            NSString *buttonTitle = [NSString stringWithFormat:@"%d",columnIndex,rowIndex];

            CGRect newFrame = CGRectMake(10 + rowIndex * 40, 60 + columnIndex * 40, 35, 35);

            UIButton  *newButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            newButton.frame = newFrame;             
            newButton.backgroundColor = [UIColor grayColor];
            [newButton setTitle:buttonTitle forState:UIControlStateNormal];
            [newButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

            // tag the button, so we know how to handle each one
            //newButton.tag = (columnIndex << 8) + rowIndex;


            //newButton =[m_buttonArray objectAtIndex:rowIndex];           
            NSLog(@"%d",[m_buttonArray count]);

            [newButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];            
            [self.view addSubview:newButton];             
        }

and when I run the project i see 6*7 grid of buttons.. but I am confused how shall I add these buttons to an array so that I can access w.r.t array,I think it requires a 2D array..so firends please help me out how shall I do this

Thanks&Regards Ranjit

Ranjit
  • 4,576
  • 11
  • 62
  • 121

1 Answers1

0

There's no grid layout in iOS, afaik.

One of your options is to lay out your interface in the interface builder: Create a new file using UIViewController subclass. Tap the .xib file in the XCode 4.x

Tap the right panel button on the top left, then select "library". Drag a UIButton over to your view and position it. Then you can copy/paste buttons.

I recommend you to find an iOS interface builder tutorial and proceed with that if you want to take this approach.

This is the simplest, yet tedious path. You would be able to visually see how your calendar looks. The downside is that this approach would require you to define 42 buttons and 42 outlets. On the plus side, you would be able to alter your .XIB file

Another way would be to create the interface programmatically an NSMutableArray and add 42 buttons there. You would add each button to your subview using a custom frame for each. This is a very error prone solution, and you will have to manually edit frame offsets/widths if you need to make changes.

I hope this helps!

Alex Stone
  • 46,408
  • 55
  • 231
  • 407
  • Hey alex thanks for your suggestion,can you please suggest me how I would go forward in implementing calendar logic,I have no clue abt it.how shall i implement calendar logic on this buttons,and whether its a simple task or time consuming..waiting for your response – Ranjit Nov 10 '11 at 07:38