我在我的應用程序中使用了20個UIButton。我在click事件中設置了所有這些UIButton的背景圖像。所有這些UIButton都保存在NSMutableArray中。這裏是代碼。如何一次刪除多個UIButtons的背景圖片?
saveBtn = [[NSMutableArray alloc] init];
for (int i=0; i<20; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(spacex, spacey, 30.0, 30.0);
idx = arc4random()%[arr count];
NSString* titre1 = [arr objectAtIndex:idx];
[btn setTitle:titre1 forState:UIControlStateNormal];
spacex = spacex + 30;
[saveBtn addObject:btn];
[self.view addSubview:btn];
}
我不成功這裏是我的代碼。
UIButton *currentButton = (UIButton *)sender;
UIImage * imgNormal = [UIImage imageNamed:@"subtabButton.png"];
[currentButton setBackgroundImage:imgNormal forState:UIControlStateNormal];
[currentButton setTitle:currentButton.titleLabel.text forState:UIControlStateNormal];
但這些20個UIButtons有3個UIButtons之間,我想,當玩家點擊這三個UIButtons之一,所有以前設置的背景圖像是從UIButtons.can刪除任何一個指導我怎樣才能做到這一點..提前。
爲什麼不能遍歷所有的UIButtons?把他們放在一個陣列中,並在他們身上。 –