Question: Tried this but only works for UIButton:

```
[btn setTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];

```

Answer: 
If you need this enough times in your code, it's nice to go ahead and extend `UIBarButtonItem` which I've done below in Swift. :)

```
import UIKit

extension UIBarButtonItem {
    func addTargetForAction(target: AnyObject, action: Selector) {
        self.target = target
        self.action = action
    }
}

```

As an example, with self as a `UIViewController`, you'd simply call:

```
self.myBarButtonItem.addTargetForAction(self, action: #selector(buttonPressed(_:))

```
For a custom `UIBarButtonItem` this works.

```
let button = UIButton(type: .custom)
button.setImage(image, for: .normal)
button.addTarget(self, action: #selector(yourFunction), for: .touchUpInside)
let barButtonItem = UIBarButtonItem(customView: button)

```

You set the target and action to the button that you are adding to your `UIBarButtonItem`.