for (int i=0; i<array.count; i++)
{
//循環添加button
UIButton * button = [custombutton initbutton:CGRectMake(i*80, 0, 80, 30) title:[[array objectAtIndex:i] valueForKey:@"typeName"]font:12 image:@"buttonCommon.png" select:@selector(touch:) who:self];
//給button添加tag值
button.tag=i+1;
if (button.tag==1)
{
[button setBackgroundImage:[UIImage imageNamed:@"buttonSelect.png"] forState:UIControlStateNormal];
}
[scro addSubview:button];
}
-(void)touch:(id)sender
{ UIButton * button = (UIButton*)sender;
//點擊button更改背景
for (int i=0; i<array.count; i++)
{ //通過tag值取到button
UIButton * butt =(UIButton *)[scro viewWithTag:i+1];
[butt setBackgroundImage:[UIImage imageNamed:@"buttonCommon.png"] forState:UIControlStateNormal];
}
[button setBackgroundImage:[UIImage imageNamed:@"buttonSelect.png"] forState:UIControlStateNormal];
}