-3

I often UIImageView when you tap some actions will be excused instead of UIButton. Because if you use UIButton, it isn't excused until you release your finger. But if you use UIImageView, the action will be excused the moment you touch UIImageView. But I'm wondering whether it is good way to make "UIButton" or not because when I use UIImageView, I set the tag of UIImageView, use touchesBegan, and check which UIImageView you tap. I'm not sure the way it good or not.

Do you use UIButton when you want to do some actions when you touch the object? And what do you think about it?

(I'm sorry I'm a beginner iOS engineer so it might be idiot question.)

Kuldeep
  • 4,466
  • 8
  • 32
  • 59
K.K.D
  • 917
  • 1
  • 12
  • 27
  • 1
    For the `UIButton`, apart from `touchUpInside` there are other gestures too. Please check. – pkc456 Apr 12 '18 at 07:00

3 Answers3

1

Because if you use UIButton, it isn't excused until you release your finger.

This is true if you have a function that is triggered at the event touchUpInside. If you use the event touchUpDown, the function will get triggered right after the user tapped the button. See here all the events: UIButton events. What's the difference?

J. Doe
  • 12,159
  • 9
  • 60
  • 114
0

I can easily be done using UIButton, you just need to use different controlEvents, for instance like so

yourButton.addTarget(self, action: #selector(yourSelector), for: .touchDown)
mag_zbc
  • 6,801
  • 14
  • 40
  • 62
0

Try it from .xib or .storyboard file. I think it will help you.

enter image description here

Community
  • 1
  • 1
Atanu Mondal
  • 1,714
  • 1
  • 24
  • 30