Set custom images to the UIBarButtonItem but it doesn't show any image

人走茶凉 提交于 2019-11-27 09:45:49

Thats because UIBarButtonItem image's default rendering mode always draw the image as a template image, ignoring its color information (UIImageRenderingModeAlwaysTemplate). Just create your image using UIImage's method imageWithRenderingMode always original.

UIImage(named: "yourImageName")!.withRenderingMode(.alwaysOriginal)

Swift 3 , 4 update

From swift 3, the method is changed to the following format

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