給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");
    
}
複製代碼
相關文章
相關標籤/搜索