xcode加载图片点击事件,图片带参数

clickx 作为一个方法被调用,表示当你点击图片的时候出发这个方法,这个方法可以自己随便写比如abc,clicky

- (IBAction)test:(id)sender {
    UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
    imageView.image=[UIImage imageNamed:@"22.png"];
    imageView.userInteractionEnabled = YES;
    [imageView setTag:2];//为了带个参数过去
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickx:)];
    [imageView addGestureRecognizer:singleTap];
    //[singleTap release];
    [self.view addSubview:imageView];
}

UITapGestureRecognizer 带过来的参数 gesture 将索引值tag给传递过来

- (IBAction)clickx:(id)sender,UITapGestureRecognizer *gesture{
   UIView *temView = [gesture view];
    NSInteger temIndex = temView.tag;
    NSLog(@"aaaa%d",temIndex);
}


This entry was posted in MAC, Xcode and tagged , . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/xcode-image-click-args/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力.
2020.03.24 评论已经全局关闭,有事加QQ聊天