我有以下问题。我有一个UIScrollView
,我有几个按钮,图标设置为这些按钮上的图像。我有一个长按识别器连接到每个按钮。如何在长按手势上的发件人按钮上显示较小的删除图标?我的目标是创建当用户想要删除特定应用程序时由iOS呈现的行为。
这是按钮(带图像)的代码:
//set the button with the image of conference here.
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(3, 3, w-5, h-5);
CALayer * l = [button layer];
[l setMasksToBounds:YES];
[l setCornerRadius:8.0];
[button setImage:thumb forState:UIControlStateNormal];
button.property = confInfo;
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
bView.tag = i;
//Add gesture recognizer to be used for deletion of conference.
UILongPressGestureRecognizer *pahGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognizerStateChanged:)];
pahGestureRecognizer.minimumPressDuration = 1.0;
[button addGestureRecognizer:pahGestureRecognizer];
此代码处于循环中(请参阅代码中的i)。我的长时间动作是这样的:
- (void)longPressGestureRecognizerStateChanged:(UIGestureRecognizer *)gestureRecognizer {
switch (gestureRecognizer.state) {
case UIGestureRecognizerStateEnded:
NSLog(@"Tapped!!!");
break;
default:
break;
}
}
如何通过我点击此操作的按钮来显示按钮右上角的较小X图像?
答案 0 :(得分:2)
您的手势识别器应通过其视图属性附加到UIButton。
case UIGestureRecognizerStateEnded:
NSLog(@"Tapped!!!");
[((UIButton*)gestureRecognizer.view) setImage:thumbWithX forState:UIControlStateNormal];
break;