我以编程方式创建标签和按钮。我关注的是longPress手势它的颜色变化。工作正常。当用户点击另一个前一个按钮并且标签颜色变得清晰时。我的按钮工作正常,但我以前的标签不清楚颜色。
- (void)handleLongPress :(UITapGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
NSLog(@"Long press Ended");
appDelegate.selectedTag =gestureRecognizer.view.tag;
} else if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
UILabel *previousLabel = (UILabel *)[self.view viewWithTag:appDelegate.selectedTag];
NSLog(@"%@",previousLabel);
previousLabel.backgroundColor =[UIColor clearColor];
UIButton *button = (UIButton *)[self.view viewWithTag:gestureRecognizer.view.tag];
button.backgroundColor =[UIColor colorWithRed:0.102 green:0.776 blue:0.557 alpha:1];
UILabel *label=(UILabel *)gestureRecognizer.view;
label.backgroundColor=[UIColor colorWithRed:0.102 green:0.776 blue:0.557 alpha:1];
UIButton *previousbutton = (UIButton *)[self.view viewWithTag:appDelegate.selectedTag];
previousbutton.backgroundColor =[UIColor clearColor];
}
}
答案 0 :(得分:0)
您的按钮和标签在" self.view"。
中有相同的标记在你的情况下,标签必须是唯一的。
答案 1 :(得分:0)
您好我认为您因UIButton和UILabel的相同标签而面临此问题。
请关注iOS: Find all controls with the same tag此链接。可能是你的问题得到解决。
一切顺利!