Is there an way to make an invisible UIButton that will still “be there” and catch touch events for my UIImageView?

后端 未结 11 2013
悲哀的现实
悲哀的现实 2020-12-25 11:41

I thought to be clever and just put an transparent UIButton over an UIImageView with the exact frame size, so that I can wire it up easily with any event I like, for example

11条回答
  •  南方客
    南方客 (楼主)
    2020-12-25 12:35

    This is what i did but with using a subclass of UIButton which i later found out should not be subclassed as per the net. My subclass was called Points

    Points *mypoint=[Points buttonWithType:UIButtonTypeCustom];

    then if you have an image you want to add to the button : [mypoint setImage:imageNamed:@"myimage"] forstate: UIControlStateNormal];

    if you dont add this image then the button will be invisible to the user but should respond to touch. Thats how i created a hotspot on my imageView inorder to have it respond to user interaction.

提交回复
热议问题