欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

给UIImageView UILabel等没有自带点击事件的view添加点击事件

程序员文章站 2024-01-15 19:18:10
...
  UIImageView * imview = [[UIImageView alloc]init];
    imview.frame = CGRectMake(10, 10, 200, 200);
    imview.backgroundColor = [UIColor blueColor];
    [self.view addSubview:imview];
    imview.userInteractionEnabled = YES;
    [imview addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(haha)]];

-(void)haha{
    
        NSLog(@"xxxxx");
    
}
复制代码

转载于:https://juejin.im/post/5a31007c6fb9a045263b95cc