[Solved] Xcode: Set a button background image to change everytime the button is pressed


Follow this sample logic .This may be useful for you.

-(void)viewDidLoad{
            isCount = 0; // int value.
          UIImage * image1 = [UIImage imageNamed:@"SampleImage1.png"];
            UIImage * image2 = [UIImage imageNamed:@"SampleImage2.png"];
            UIImage * image3 = [UIImage imageNamed:@"SampleImage3.png"];
            UIImage * image4 = [UIImage imageNamed:@"SampleImage4..png"];
            UIImage * image5 = [UIImage imageNamed:@"SampleImage5.png"];
            UIImage * image6 = [UIImage imageNamed:@"SampleImage6.png"];
            UIImage * image7 = [UIImage imageNamed:@"SampleImage7.png"];
            UIImage * image8 = [UIImage imageNamed:@"SampleImage8.png"];
            UIImage * image9 = [UIImage imageNamed:@"SampleImage9.jpg"];
            imagesArray = [[NSMutableArray alloc]initWithObjects:image1,image2,image3,image4,image5,image6,image7,image8,image9, nil];

        }   
     -(IBAction)Hexa1Button:(id)sender{
      if( isCount < [imagesArray count]){ 
      [Hexa1Button setBackgroundImage:[imagesArray objectAtIndex:isCount] forState:UIControlStateNormal];
     isCount ++;
          }  
     }

3

solved Xcode: Set a button background image to change everytime the button is pressed