通过xcode5的xib进行设计时,导航栏按钮项目图像颜色不同 [英] Navigation bar button item image color is different when design through xib of xcode5

查看:140
本文介绍了通过xcode5的xib进行设计时,导航栏按钮项目图像颜色不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xib创建导航栏按钮但是当我要将图像设置为条形按钮时,图像颜色与原始图像不同。

I am creating navigation bar button using xib but when i going to set image to bar button then image colour is different as original image.

这是我的orignal图像。

Here is my orignal image.

在导航栏按钮项目上添加该图像后,它看起来像这样

And after adding that image on navigation bar button item than it look like this

推荐答案

首先,我同意@Desdenova的评论。

这两个图像看起来不一样,每个线条有一个硬直角边缘,另一个是圆形。

确保你正在使用正确的图像文件。

如果是这种情况,很棒,问题解决了,而没有偏离 xib 实现。如果没有,只需按编程方式进行(根据@shankars代码)。

但另外需要注意的是,我遇到了将自定义图像文件设置为按钮的问题,其中图像被调整了... make将图像设置为按钮时,一定要使用 UIImageRenderingModeAlwaysOriginal

First, I agree with @Desdenova's comment.
The two images do not look the same, one has hard right angle edges for each line, and the other rounded.
Make sure you are using the correct image file.
If this is the case, awesome, problem solved without deviating from your xib implementation. If not, just do it programmatically (as per @shankars code).
But another thing to note, I've run into problems setting custom image files to buttons, where the image gets tweaked... make sure to use UIImageRenderingModeAlwaysOriginal when setting the image to the button:

Objective-C:

[button setImage:[[UIImage imageNamed:@"imageName.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];

Swift:

someBarButtonItem.image = UIImage(named: "yourPictureName")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

Swift 3:

someBarButtonItem.image = UIImage(named:"myImage")?.withRenderingMode(.alwaysOriginal)

这篇关于通过xcode5的xib进行设计时,导航栏按钮项目图像颜色不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆