博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
给ImageView添加触发效果
阅读量:7113 次
发布时间:2019-06-28

本文共 979 字,大约阅读时间需要 3 分钟。

hot3.png

 UIImageView * headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10,10 ,40,40)];                headImageView.clipsToBounds = YES;                headImageView.layer.cornerRadius = 20                //ImageView默认是不可触发的,需要开启                headImageView.userInteractionEnabled = YES;                [cell.contentView addSubview:headImageView];              //给imageView添加点击触发                UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headViewAction:)];                [headImageView addGestureRecognizer:tap];              //因为UIImageView没有tag值,所以放到View上,如果是View的话可直接设tag值                UIView *singleView = [tap view];                singleView.tag = 100 +i;//方法                - (void)headViewAction:(UIGestureRecognizer *)send{    //拿到tag值    UITapGestureRecognizer * tap = (UITapGestureRecognizer *)send;    NSInteger i = [tap view].tag;}

UIView也是和上面基本相同。

转载于:https://my.oschina.net/langzhouzhou1/blog/659450

你可能感兴趣的文章