Sebastien Desemberg
Sebastien Desemberg

Reputation: 321

Keep original colors of UIBarButtonItem's UIImage

How do I position a full colour logo to the top right side? When I try it goes one colour. When positioning in the center I don't get that issue.

Right side makes the logo blue:

self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage.init(named: "inteliPOS_Iconic_Mark")

But in the title it's fine:

self.navigationItem.titleView = UIImageView(image: UIImage(named: "inteliPOS_Iconic_Mark"))

Upvotes: 0

Views: 64

Answers (1)

joern
joern

Reputation: 27620

You can use a UIBarButtonItem with a UIImageView as custom view. That will keep the color of your image:

let logoImageView = UIImageView(image: UIImage(named: "inteliPOS_Iconic_Mark"))
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: logoImageView)

If you use UIBarButtonItem(image:) the image will be used as a template and tinted according to the navigation bar's tint color.

When you use UIBarButtonItem(customView:) the image will be used as is.

Upvotes: 2

Related Questions