UIImageView as button

后端 未结 5 1144
庸人自扰
庸人自扰 2020-12-12 17:48

I\'m trying to make a UIImageView accept actions and fire them everytime it clicked on the UIImageVie, but i\'m having hard time in getting it to work, please help me out

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 18:09

    i am not a pro but you can use button for this

    UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
    imageButton.frame = CGRectMake(0, 0, 200, 200);
    [imageButton setImage:[UIImage imageNamed:@"Your_Image.png"] forState:UIControlStateNormal];
    imageButton.adjustsImageWhenHighlighted = NO;
    [imageButton addTarget:self action:@selector(myAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:imageButton];
    

提交回复
热议问题