change image on click of button in objective c

前端 未结 3 476
粉色の甜心
粉色の甜心 2021-01-27 15:51

i draged 3 button in my .xib file (btn1,btn2,btn3 respectively) and initially i given default image to them, first.png

now when user clicks on btn1, image of btn1 should

3条回答
  •  灰色年华
    2021-01-27 16:12

    You have to set button action method code

    -(IBAction)btnClked:(id)sender
    {
      [btn1 setImage:[UIImage imageNamed:@"first.png"] forState:UIControlStateNormal];
      [btn2 setImage:[UIImage imageNamed:@"first.png"] forState:UIControlStateNormal];
      [btn3 setImage:[UIImage imageNamed:@"first.png"] forState:UIControlStateNormal];
    
      UIButton *btn=(UIButton *)sender;
    
      [btn setImage:[UIImage imageNamed:@"second.png"] forState:UIControlStateNormal];
    }
    

提交回复
热议问题