美文网首页iOS
iOS 给UIImageview加点击事件

iOS 给UIImageview加点击事件

作者: 丶绅士丿丨丨 | 来源:发表于2015-10-15 17:29 被阅读13183次

    //初始化一个UIImageView的对象
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];

    imageView.image = [UIImageimageNamed:@"filter_laozhaopian_a.png"];

    imageView.userInteractionEnabled = YES;//打开用户交互
    //初始化一个手势
    UIGestureRecognizer *singleTap = [[UIGestureRecognizeralloc] initWithTarget:self action:@selector(singleTapAction:)];
    //为图片添加手势
    [imageView addGestureRecognizer:singleTap];
    //显示
    [self.view addSubview:imageView];
    //点击事件
    -(void)singleTapAction:(UIGestureRecognizer *)
    {
    //具体的实现
    }

    相关文章

      网友评论

        本文标题:iOS 给UIImageview加点击事件

        本文链接:https://www.haomeiwen.com/subject/ljtacttx.html