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

  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");
    
}
复制代码
相关文章
相关标签/搜索