我有三个按钮图像,我想检查它们之间的条件。当我点击按钮1意味着背景图像变成蓝色。同时我点击按钮1将移动到正常状态的白色。另外两个按钮相同。对于该过程,我使用此代码。 [tempBtn setSelected:! tempBtn.selected];
如何检查三个按钮的状态
ButtonImageSelected = [UIImage imageNamed:@"lblue.png"];
ButtonImage = [UIImage imageNamed:@"l.png"];
button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(80, 27, 36, 36);
[button1 setBackgroundImage:ButtonImage forState:UIControlStateNormal];
button1.tag = 1;
[button1 setBackgroundImage:ButtonImageSelected
forState:UIControlStateSelected];
button1.userInteractionEnabled = YES;
[button1 addTarget:self
action:@selector(button1Selector:)
forControlEvents:UIControlEventTouchDown];
[cell.contentView addSubview:button1];
另外两个按钮相同,按钮1
我的条件是:当按钮1被点击装置按钮3不应该改变。当按钮3被点击意味着按钮1不应该改变。按钮2可以在两种条件中选择。我使用下面的代码来检查条件,但是它的工作不正确。
- (void)select_id:(UIButton *)tempBtn {
if (tempBtn.tag == 1) {
button3.userInteractionEnabled = NO;
[tempBtn setSelected:!tempBtn.selected];
} else if (tempBtn.tag == 3) {
button1.userInteractionEnabled = NO;
[tempBtn setSelected:!tempBtn.selected];
}
}
帮我看看如何检查条件。在上面的方法中。
其还没有工作对我来说.. – 2015-02-11 06:57:09
我已经编辑了答案;事实证明,这种情况并没有正确比较图像。它已被更新和修复。确保在运行代码之前遵循所有步骤。 – 2015-02-11 07:31:14