5

ios flag 做按标识钮切换,有点问题请帮忙

先定义bool _flag 然后如下图中代码,一组按钮!

_flag = !_flag;
if (_flag) {
[_btn1 setBackgroundImage:[UIImage imageNamed:@"buttn2.png"] forState:UIControlStateNormal];
[_btn2 setBackgroundImage:[UIImage imageNamed:@"buttn1.png"] forState:UIControlStateNormal];
[_btn3 setBackgroundImage:[UIImage imageNamed:@"buttn1.png"] forState:UIControlStateNormal];
[_btn4 setBackgroundImage:[UIImage imageNamed:@"buttn1.png"] forState:UIControlStateNormal];
[_btn5 setBackgroundImage:[UIImage imageNamed:@"buttn1.png"] forState:UIControlStateNormal];
[_btn6 setBackgroundImage:[UIImage imageNamed:@"buttn1.png"] forState:UIControlStateNormal];
[_btn7 setBackgroundImage:[UIImage imageNamed:@"buttn1.png"] forState:UIControlStateNormal];
[_btn8 setBackgroundImage:[UIImage imageNamed:@"buttn1.png"] forState:UIControlStateNormal];
[_btn9 setBackgroundImage:[UIImage imageNamed:@"buttn1.png"] forState:UIControlStateNormal];
[_btn10 setBackgroundImage:[UIImage imageNamed:@"buttn1.png"] forState:UIControlStateNormal];
[_btn11 setBackgroundImage:[UIImage imageNamed:@"buttn1.png"] forState:UIControlStateNormal];
[_btn12 setBackgroundImage:[UIImage imageNamed:@"buttn1.png"] forState:UIControlStateNormal];
}
else
{
[_btn1 setBackgroundImage:[UIImage imageNamed:@"buttn1.png"] forState:UIControlStateNormal];

}

是为了,选中按钮后 按钮会显示不一样的图片 好出分开来,但是有个问题,比如说按钮1在显示buttn2的时候,点击别的按钮, 按钮1是会显示buttn1! 但是当再次点击按钮1的时候,按钮1会先显示1次buttn1,再才能达到我想要的效果!中间就会有2次显示buttn1 请问这怎么再定义下

查看全部
c3812600
c3812600
2015/08/07 02:54
  • flag
  • ios
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复