-1

Can anyone help with how to make a button unselected after I press another button.

I have 3 buttons and do not know how to make previous button look like unselected in switch case, after touch they change state to selected Yes and change their pics.

-(IBAction)pencilPressed:(id)sender{
    UIButton *pressedButton = (UIButton*)sender;
    switch(pressedButton.tag)
    {
    case 0:
          pressedButton.selected=YES;
          red = 255.0/255.255;
          green = 0.0/255.255;
          blue = 0.0/255;
    break;
    case 1:
          pressedButton.selected=YES;
          red = 0.0/255.255;
          green = 0.0/255.255;
          blue = 255.0/255;
    }
}
4

1 回答 1

0

切换前:

for(UIView *v in sender.superview.subviews) {
    if([v isKindOfClass:[UIButton class]]) {
           [v setSelected:NO];
    }
}

假设所有按钮都彼此相邻:) 否则你需要 IBOutlets 到按钮

于 2012-11-11T10:21:07.113 回答