gpt4 book ai didi

ios - 在长按手势时在 UIButton 中显示图像

转载 作者:可可西里 更新时间:2023-11-01 05:57:51 25 4
gpt4 key购买 nike

我有以下问题。我有一个 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)。我的长按 Action 是这样的:

- (void)longPressGestureRecognizerStateChanged:(UIGestureRecognizer *)gestureRecognizer {

switch (gestureRecognizer.state) {

case UIGestureRecognizerStateEnded:
NSLog(@"Tapped!!!");
break;

default:
break;
}
}

如何将我点击的按钮传递给此操作以在按钮的右上角显示较小的 X 图像?

最佳答案

您的手势识别器应通过其 View 属性附加到 UIButton。

case UIGestureRecognizerStateEnded:
NSLog(@"Tapped!!!");
[((UIButton*)gestureRecognizer.view) setImage:thumbWithX forState:UIControlStateNormal];
break;

关于ios - 在长按手势时在 UIButton 中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9021229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com