Navigation bar button image not showing in Swift

半腔热情 提交于 2019-12-30 17:27:07

问题


I'm back again.

I'm writing an app in Swift using Xcode 7. I've added a navigation controller and on top of that a navigation item, and then a bar button. I'm trying to change the image of the bar button to a png that I've imported into Xcode. However, it just shows this in the design and also when I run the app. It just shows a blue smudge in the navigation area.

I've tried importing the image into the project and also into images.xcassets with the same results.

Anyone know what may be wrong here?

Here's the image I've been trying to add and the settings I currently have.

Settings:


回答1:


The way to resolve navigation button images appearing as blue is to select the image set in Assets.

And then choose Original Image from the Render As select options.




回答2:


You should have a image with alpha.(The sample image you posted has white background). Also you should set the image with template mode. I dont know how to do that in Interface builder. This is a sample code to convert the image to template.

var image = UIImage(named: "").imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)


来源:https://stackoverflow.com/questions/32827704/navigation-bar-button-image-not-showing-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!