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 p_w_picpath:@”buttonCommon.png” select:@selector(touch:) who:self];

        //button添加tag

        button.tag=i+1;

        if (button.tag==1)

        {

            [button setBackgroundImage:[UIImage p_w_picpathNamed:@”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 p_w_picpathNamed:@”buttonCommon.png”] forState:UIControlStateNormal];

            }

           [button setBackgroundImage:[UIImage p_w_picpathNamed:@”buttonSelect.png”] forState:UIControlStateNormal];    

}