在我的应用程序中,我需要用户能够尽快刷20个按钮。我已经设置了UIswipegesture,但我不知道如何更改按钮的颜色,或者只是在按正确的方式滑动后让它消失。例如第一个按钮表示左<<它有2个滑动手势我需要按钮消失或改变颜色,一旦用户向左滑动。
任何帮助将不胜感激:)
答案 0 :(得分:1)
您可以设置UIButton的背景颜色 btnYourButton.backgroundColor = [UIColor greyColor];
或者您可以通过
隐藏按钮btnYourButton.hidden = YES;
答案 1 :(得分:1)
在你的.h
中声明@interface ViewController : UIViewController
{
NSMutableArray *arrButtonsInView;
}
-(void)handleSwipe : (UIGestureRecognizer*) gr;
在.m的ViewDidload中,添加以下代码
arrButtonsInView = [[NSMutableArray alloc]init];
for (id i in [self.view subviews]) {
if ([i isKindOfClass:[UIButton class]]) {
UIButton *btn = i;
btn.tag = [[self.view subviews] indexOfObject:i];
[arrButtonsInView addObject:btn];
UISwipeGestureRecognizer *sw = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipe:)];
sw.direction = UISwipeGestureRecognizerDirectionLeft;
[btn addGestureRecognizer:sw];
}
}
并实现 - (void)handleSwipe:(UIGestureRecognizer *)gr;
-(void)handleSwipe:(UIGestureRecognizer *)gr {
UIButton *btn = [arrButtonsInView objectAtIndex:gr.view.tag];
[btn setBackgroundColor:[UIColor grayColor]];
}