I try to make a menu with UIButton and I just want to be able to select only one button at the time. Witch means when I select a button it's automatically deselect the other one. But it's acting weird and i don't understand why.
When I select a button from the menu it's became red and when I select a another one they are both red but I have to click 2 times on the fist button to put it black and it the same thing for the second button. The problem is when I click on the second button the first should has become black instead of stay red.
This function is called when a button is pressed with addTarget.
- (void)putInSelectedMode:(id)sender {
NSLog(@"[%d] %s => %s", __LINE__, __FUNCTION__, __FILE__);
if ([sender isKindOfClass:[UIButton class]]) {
sender = (UIButton*)sender;
if ([sender isSelected])
{
[sender setSelected:NO];
[[sender layer] setShadowColor:[[UIColor clearColor] CGColor]];
[[sender layer] setBorderWidth:0.0f];
}
else {
UIButton *btn = nil;
NSArray *subviews = [self subviews];
for (btn in subviews) {
if ([btn isKindOfClass:[UIButton class]]) {
[btn setSelected:NO];
}
}
[[sender layer] setBorderWidth:5.0f开发者_如何学Go];
[[sender layer] setBorderColor:[[UIColor redColor] CGColor]];
[[sender layer] setOpaque:NO];
[sender setSelected:YES];
}
}
}
精彩评论