Search code examples
iosswiftuinavigationcontrollernavigationbar

Custom icons in navigation bar Swift 3


I have an issue with my custom button in Swift 3, I added into the Assets folder, in the ViewController and in the VC the icon is showed, but when I view in the simulator and in my phone the item shows only the form but not show the color and the icon itself.

Here is the image in the simulator and in my phone:

enter image description here

Here my code:

override func viewDidLoad() {
    super.viewDidLoad()

    navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style: .done, target: nil, action: nil)
    navigationController?.navigationBar.backIndicatorImage = #imageLiteral(resourceName: "back")
    navigationController?.navigationBar.backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "back")

And for last here is the button icon:

enter image description here

Here in Photoshop enter image description here

In xcode:

enter image description here


Solution

  • Make sure you follow the guidelines for creating Navigation Bar Items. Just guessing from your image it seems that you want the dark area to be colored and the white arrow to show as white or clear? In order to achieve this you need to make the white arrow transparent. Wherever your icon has pixel information will be colored in.