tags:

views:

56

answers:

2

How to create Grid of Buttons on iphone. 10/10 matrix...

I found NSMatrix for MAC ... Not for iphone...

any alternative way to create grid of button on my view.

@Thanks in advance.

+1  A: 

Manually?

   int rows = 10;
    int cols = 10;

    float gridWidth = 320.0;
    float gridHeight = 320.0;

    float buttonWidth = 28.0;
    float buttonHeight = 28.0;

    float gapHorizontal = (gridWidth - (buttonWidth * rows)) / (rows + 1);
    float gapVertical = (gridHeight - (buttonHeight * cols)) / (cols + 1);

    float offsetX;
    float offsetY;

    int count = 0;

    do {
        offsetX = gapHorizontal + ((count % rows) * (buttonWidth + gapHorizontal));
        offsetY = gapVertical + ((count / rows) * (buttonHeight + gapVertical));

        UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(offsetX, offsetY, buttonWidth, buttonHeight)];
        aView.backgroundColor = [UIColor redColor];
        [self.view addSubview:aView];
        [aView release];

        offsetX+= buttonWidth + gapHorizontal;

        count++;

    } while(count < rows * cols);
Joseph Tura
Thanks @joseph Tura.
kiran kumar
I am planing to do mineSweeper ... game on iphone. I am beginner with iphone stuff.
kiran kumar
It's fun once you get the hang of it. :)
Joseph Tura
+1  A: 

Also check out AQGridView. I guess it's pretty much what you are looking for. And more.

Joseph Tura
Thanks For Examples from AQGridview ....
kiran kumar