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

后端 未结 11 2050
悲哀的现实
悲哀的现实 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:33

    In addition to UIButtonTypeCustom, I set the button text colors to the following:

    [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
    [button setTitleShadowColor:[UIColor clearColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor clearColor] forState:UIControlStateHighlighted];
    [button setTitleShadowColor:[UIColor clearColor] forState:UIControlStateHighlighted];
    

提交回复
热议问题