0
I need to add two buttons in the navigation bar of my app, but what I need to use an external image (already imported to the project) it does not appear.
override func viewDidLoad() {
super.viewDidLoad()
//Esse botão aparece (icone da própria biblioteca)
let rightShareBarButtonItem:UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action, target: self, action: #selector(ViewController.shareTapped))
//Esse ícone não aparece, estou tentando carregar uma imagem interna - já importada ao projeto
let rightInfoBarButtonItem:UIBarButtonItem = UIBarButtonItem(image: UIImage(named: "info.png"), style: UIBarButtonItemStyle.plain, target: self, action: #selector(ViewController.infoTapped))
self.navigationItem.setRightBarButtonItems([rightInfoBarButtonItem, rightShareBarButtonItem], animated: true)
}
One guess is that there isn’t enough space for the two buttons on this side of the bar. Have you tried adding just the custom button or adding it first to see if it appears? I didn’t notice anything wrong in the code...
– Andreza Cristina da Silva
So, I’ve put two buttons that have in the Xcode library itself and both appeared, including already put text in which its size is larger than the icon and tb appeared, the only thing that does not appear are external images...
– Tiago Segato
The image is there in xcassets exactly with the name you are calling her, right?
– Andreza Cristina da Silva
I’m new to iOS development and didn’t know that icons should be on xcassets, for me they were the same as the other images where we just add to the project. But I created a new Assets.xcassets and it worked. Again thank you very much, it completely solved my problem.
– Tiago Segato