iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 在长按手势的UIButton中显示图像大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_262_4@ 我有以下问题.我有一个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图像?

解决方法

您的手势识别器应通过其视图属性附加到UIButton.

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

大佬总结

以上是大佬教程为你收集整理的ios – 在长按手势的UIButton中显示图像全部内容,希望文章能够帮你解决ios – 在长按手势的UIButton中显示图像所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。