In Swift :
let infoImage = UIImage(named: "my-icon") let imgWidth = infoImage?.size.width let imgHeight = infoImage?.size.height let button:UIButton = UIButton(frame: CGRect(x: 0,y: 0,width: imgWidth!, height: imgHeight!)) button.setBackgroundImage(infoImage, forState: .Normal) button.addTarget(self, action: Selector("openInfo"), forControlEvents: UIControlEvents.TouchUpInside) self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: button)
PS The constructor of UIBarButtonItem(image:style:target:action:) works only for transparent PNG, I also need to set the tintcolor button other than clearColor.
King wizard
source share