StevenZ
StevenZ

Reputation: 7113

Programmatically Setting UINavigation Bar Button

How can I set the UINavigation Bar Button to a particular image programmatically using Swift?enter image description here?

Upvotes: 1

Views: 1046

Answers (1)

Yohan
Yohan

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

Related Questions