次のコードを使用して、配列を含む一連のUIButtonを追加しています。現在、ボタン同士が近すぎるため、各ボタンの間に間隔を空ける方法があるかどうか疑問に思いました。
これが私のコードであり、助けてくれてありがとう:
// Create buttons for the sliding category menu.
buttonArray = [NSMutableArray array];
myImages = [NSArray arrayWithObjects:@"category-cafe-unsel.png", @"category-food-unsel.png", @"category-clothing-unsel.png", @"category-health-unsel.png", @"category-tech-unsel_phone.png" , @"category-tech2-unsel.png", @"catefory-theatre-unsel.png", @"category-travel-unsel.png", nil];
myImagesSel = [NSArray arrayWithObjects:@"category-cafe-sel.png", @"category-food-sel.png", @"category-clothing-sel.png", @"category-health-sel.png", @"category-tech-sel_phone.png" , @"category-tech2-sel.png", @"catefory-theatre-sel.png", @"category-travel-sel.png", nil];
// only create the amount of buttons based on the image array count
for(int i = 0;i < [myImages count]; i++)
{
// Custom UIButton
btn.tag = i+1;
btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0.0f, 20.0f, 52.0f, 52.0f)];
[btn setTitle:[NSString stringWithFormat:@"Button %d", i] forState:UIControlStateNormal];
[btn setImage:[UIImage imageNamed:[myImages objectAtIndex:i]] forState:UIControlStateNormal];
[btn setImage:[UIImage imageNamed:[myImagesSel objectAtIndex:i]] forState:UIControlStateSelected];
NSLog(@"The button title is %@ ", btn.titleLabel.text);
[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[buttonArray addObject:btn];
// NSLog(@"Button tag is: %d",btn.tag);
}
UIImageView *blackColor = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"blackColor.png"]];
// initialize the slide menu by passing a suitable frame, background color and an array of buttons.
slideMenuView = [[SlideMenuView alloc] initWithFrameColorAndButtons:CGRectMake(0.0f, 0.0f, 320.0f, 80.0f) backgroundColor:[UIColor clearColor] buttons:buttonArray];