title: IOS callback on UIButton click
body: <p>I have a button which is used in many screens of my app. I want to implement a custom button with a custom image and a callback when the button is pressed.</p>
  
  <p>I'm used to java but I don't know how to solve this in iOS. I have read about Category and Subclassing, but I'm still not sure.</p>
  
  <p>Does anyone have an example?. Or what's the best solution for that?. I would really appreciate any help.</p>
  
  <p>What I have done (Thanks @Aris):</p>
  
  <p>.h file</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface UIButton (MyUIButton)
  
  + (UIButton *)customButtonWithTarget:(id)target;
  
  @end
  </code></pre>
  
  <p>.m file</p>
  
  <pre><code>#import "UIButton+MyUIButton.h"
  
  @implementation UIButton (MyUIButton)
  
  + (UIButton *)customButtonWithTarget:(id)target{
      UIButton *button_ = [UIButton buttonWithType:UIButtonTypeSystem];
      [button_ setFrame:CGRectMake(0, 0, 120, 44)];
      [button_ setBackgroundImage:[UIImage imageNamed:@"button_image.png"] forState:UIControlStateNormal];
  
      [button_ addTarget:target
                  action:@selector(event_button_click:)
        forControlEvents:UIControlEventTouchUpInside];
  
      return button_;
  }
  
  @end
  </code></pre>
  
  <p>In my ViewController:</p>
  
  <pre><code>#import "UIButton+MyUIButton.h"
  
  - (void)viewDidLoad {
      [super viewDidLoad];
  UIButton *myButton = [UIButton customButtonWithTarget:self];
      [self.view addSubview:myButton];
  
  }
  
  -(void)event_button_click
  {
      // code here
  }
  </code></pre>
  
  <p>I get this error : <code>'-[ViewController event_button_click:]: unrecognized selector sent to instance 0x78e5df10'
  </code></p>