I am trying to subclass the UIButton to create a “smarter” button that contains logic for handling the click event.
What is the best way to achieve this? Do I simply need to override an onClick method? Or do I need to register an event handler (and if so, where should this be done seeing as there are many ways to init a UIButton?)
I think there are better solutions to this problem than what you’ve proposed, but to answer your question directly: A subclass of UIButton observes touch events the same way that everyone else observes touch events.
Important note: you can’t use
[UIButton buttonWithType:]to create your button, you’ve got to useinitorinitWithFrame:. Even though UIButton has the convenience initializer,initWithFrame:is still the designated initializer.