Reputation: 7113
How can I set the UINavigation Bar Button to a particular image programmatically using Swift??
Upvotes: 1
Views: 1046
Reputation: 1108
let rightButton: UIButton = UIButton.buttonWithType(UIButtonType.Custom)
rightButton.frame = CGRectMake(0, 0, 40, 40) ;
rightButton.setImage(UIImage(named:"ImageName.png"), forState: UIControlState.Normal)
rightButton.addTarget(self, action: "rightNavButtonClick:", forControlEvents: UIControlEvents.TouchUpInside)
var rightBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: rightButton)
self.navigationItem.setLeftBarButtonItem(rightBarButtonItem, animated: false);
Try this this should work!!
Upvotes: 1