Matt Spoon
Matt Spoon

Reputation: 2830

Changing the identifier of a UIBarButton Item to an image in swift

In an iOS app I am making, I have set the identifier of a bar button item programmatically using:

homeTitleBar.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Trash, target: self, action: nil)

Which changes the button to a trash can.

My question is, after that, how can I then change it to a custom image.

homeTitleBar.leftBarButtonItem?.image = UIImage(named: "settingsIcon")

does not seem to be working.

Upvotes: 0

Views: 437

Answers (1)

Leo
Leo

Reputation: 24714

Try

homeTitleBar.leftBarButtonItem = UIBarButtonItem(image:UIImage(named: "settingsIcon"), style: UIBarButtonItemStyle.Plain, target: self, action: nil)

Upvotes: 2

Related Questions