如何选中取消选中单选按钮?

时间:2014-03-28 13:07:02

标签: ios image uibutton

我正在使用按钮中的图像来制作按钮单选按钮。我可以通过更改图像来检查它,但我无法取消选中它。请帮我。我在按钮操作中使用此代码

[sender setImage:[UIImage imageNamed:@"check2.png"] forState:UIControlStateNormal];

1 个答案:

答案 0 :(得分:0)

您将在viewController中存储按钮的状态...

BOOL checked;

-(void)viewDidLoad {
    checked = YES;  //Set depending on your initial state
}

-(IBACtion)pressed:(UIButton *)sender {
    checked = !checked;
    [sender setImage:[UIImage imageNamed:((checked) ? @"check2.png" : @"NOTCHECKEDIMAGE.png")] forState:UIControlStateNormal];
}