2017-06-20 71 views
0

just showing blue and not image literal迅速的Xcode - navigationitem.rightbarbuttonitem不显示虽然刚刚出现蓝色

我rightBarButtonItem只是呈现蓝色,而不是像字面字面形象?

NavigationItem.rightBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "Contacts Book"), style: .plain, target: self, action: #selector(handleNewMessage)) 
+0

是否检查这段代码被破发点执行?你可以改变图像文字到旧式的UIImage(名为:“ImageName”)并试一试吗? –

+0

@方明宁 - 走向老式的方式给出了相同的结果 – bennypalmer661

回答

0

我认为这是安全的,假设这不是一个透明背景的PNG。

barButtonItems采用PNG格式,并使用默认的蓝色填充每个现有的像素。

您可以更改颜色,但我假设您不希望任何其他块取代蓝色。

您可以找到一种方法来制作这不是一个酒吧按钮项目,或者您可以编辑您的图像,使背景了。

事情是这样的:

enter image description here

工程比更好的东西是这样的:

enter image description here

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. 

enter image description here

+0

财产检查员在哪里? @brijesh Shiroya – bennypalmer661

+0

看到更新的答案! –

0
it worked by doing this 

    NavigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named:"Grape")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(handleNewMessage)) 

现在它显示的实际图像,而不仅仅是一个完整的蓝色图像