0
我有兩個UIButtons。它們表現得像複選框(兩個按鈕都可以一次選擇)。但我想只有一個按鈕可以選擇在(如單選按鈕)。我該怎麼做? 這是我如何實現複選框按鈕功能。如何實現單選按鈕行爲?
if ([btnAnswer1 isSelected]) {
[btnAnswer1 setBackgroundImage:[UIImage imageNamed:@"checkbox_unchecked.png"] forState:UIControlStateNormal];
[btnAnswer1 setSelected:NO];
}else {
[btnAnswer1 setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateSelected];
[btnAnswer1 setSelected:YES];
}
if ([btnAnswer2 isSelected]) {
[btnAnswer2 setBackgroundImage:[UIImage imageNamed:@"checkbox_unchecked.png"] forState:UIControlStateNormal];
[btnAnswer2 setSelected:NO];
}else {
[btnAnswer2 setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateSelected];
[btnAnswer2 setSelected:YES];
}
也許,使用'UISegmentedControl'會更好? – kpower
閱讀此博客.... http://www.developers-life.com/radio-buttons-in-iphone-application.html它可以幫助你... – PJR