-1

I create 15 imagebutton into an scrollerview,but have only 1 columns, i want to change row for (4 rows * 4 columns)

How can i do that?? Please give me some advance,Thank you..

NSUInteger booknumber;
for (booknumber = 1; booknumber <= 15; booknumber++) {
   UIButton *button = [self createBtn:booknumber orgx:orgx orgy:orgy];
}

orgx += 100;
orgy += 0;

orgx++;
[mFavorites addSubview:button];


- (UIButton*)createBtn:(int)day orgx:(CGFloat)orgx orgy:(CGFloat)orgy{
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"backplane.png"] forState:UIControlStateNormal];
    button.frame = CGRectMake(orgx, orgy, 75, 113);

    return button;
}
Alice Chen
  • 231
  • 1
  • 2
  • 11
  • [What have you tried?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – CodaFi May 09 '12 at 03:50
  • I try to use for{},but load nothing(I have no idea),also need to study more than,please give me some advance.. – Alice Chen May 09 '12 at 03:52
  • 1
    Put your code up. Questions like these make it look like you did not research and came here to get us to do your work. At least with code, it shows you've tried. (BTW, by even showing code, you're in the minority. Usually, we just get these kinds of questions with no effort whatsoever on the part of the asker). – CodaFi May 09 '12 at 03:56
  • calculation of origin is not proper, every time you just increasing x, while you want a grid structure? – rishi May 09 '12 at 05:21
  • you can check this out for reference - http://stackoverflow.com/questions/5140710/how-to-design-and-create-a-gridview-using-uiscrollview-or-uitableview – rishi May 09 '12 at 05:24

1 Answers1

0

Try that:

int booknumber = 1;
for (int i = 0; i < 4; i++) {
  for (int j = 0; j < 4; j++) {
    int orgX = i * 100;
    int orgY = j * 100;
    if (i == 3 && j == 3) return;
    UIButton *button = [self createBtn:booknumber orgx:orgX orgy:orgY];
    [mFavorites addSubview:button];
    booknumber++;
  }
}

Hope it helps

Novarg
  • 7,390
  • 3
  • 38
  • 74