just showing blue and not image literal
我的rightBarButtonItem只是显示蓝色而不是图像文字?
NavigationItem.rightBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "Contacts Book"), style: .plain, target: self, action: #selector(handleNewMessage))
答案 0 :(得分:0)
我认为可以安全地假设这不是具有透明背景的png。
barButtonItems获取png并用默认颜色蓝色填充每个现有像素。
您可以更改颜色,但我认为您不希望任何其他块代替蓝色。
您可以找到一种方法,使其不是条形按钮项目,也可以编辑图像以显示背景。
这样的事情:
比这样的效果更好:
答案 1 :(得分:0)
您需要设置以下图片的属性:
Step1:Go to Assets.xcssets
Step2:Select your imageset
Step3:Go to property inspector
Step4:In imageset you need to set Original Image into Render as property.
答案 2 :(得分:0)
it worked by doing this
NavigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named:"Grape")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(handleNewMessage))
现在它显示实际图像而不仅仅是完整的蓝色图像