
Hi, can any one please explain how to add space between UIButtons in iPhone SDK. Actually i am creating Multiple UIButton's and added them to my UIScrollView. But problem is that those buttons are placed over each other. Please tell me how can i set fix margin between buttons.
Thanks!

//Creating UIButtons
int offset = 0;
for (int row = 0; row<10; row++){
for (int col = 0; col<2;col++) {
offset +=0;
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
aButton.frame = CGRectMake(5+col*150+offset,10+row*190, 160, 180);
aButton.bounds = CGRectMake(5, 0, 140.0, 180.0);
UIImage *buttonImageNormal = [UIImage imageNamed:@"button3.png"];
[aButton setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
[aButton setTitle:@"Play" forState:UIControlStateNormal];
[aButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.iScrollView addSubview:aButton];
}
}

Hello,
Can you please comment the code, I do not understand how the code helps, I am trying to create a multiple buttons on only the x axis and want to include spaces between each button, this is what i have so far can anyone help.
NSMutableArray* buttonArray = [[NSMutableArray alloc] init];
int offset = 0;
for(int i = 0; i < 6; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake((0+offset), 0, 55, 55)];
[btn setTitle:[NSString stringWithFormat:@"Button %d", i+1] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[buttonArray addObject:btn];
//move button by offset offset += 10;
[btn release];
}
Can anyone help?

sorry the offset += 10; is not commented just posted like that see below agin for correct code
NSMutableArray* buttonArray = [[NSMutableArray alloc] init];
int offset = 0;
for(int i = 0; i < 6; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake((0+offset), 0, 55, 55)];
[btn setTitle:[NSString stringWithFormat:@"Button %d", i+1] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[buttonArray addObject:btn];
//move button by offset offset += 10;
[btn release];
}

NSMutableArray* buttonArray = [[NSMutableArray alloc] init];
int offset = 0;
for(int i = 0; i < 6; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake((0+offset), 0, 55, 55)];
[btn setTitle:[NSString stringWithFormat:@"Button %d", i+1] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[buttonArray addObject:btn];
offset += 10;
[btn release];
}