Iphone uibarbuttonite黑色而非白色

Iphone uibarbuttonite黑色而非白色,iphone,image,uibutton,Iphone,Image,Uibutton,我有那个导航控制器,我通过代码添加了1个按钮,如下所示: UIBarButtonItem *configButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"config.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(showConfigWindow)]; self.navigationItem.leftBarBut

我有那个导航控制器,我通过代码添加了1个按钮,如下所示:

UIBarButtonItem *configButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"config.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(showConfigWindow)]; 
self.navigationItem.leftBarButtonItem = configButton;
它工作正常,但图标是黑色而不是白色

如果我使用这个:

UIBarButtonItem *configButton = [[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStyleBordered target:self action:@selector(showConfigWindow)];
文本以白色正确显示

图标没有问题,因为我正在通过interface builder使用它们,它们显示在右侧。

UIBarButtonItem根据图像alpha值以灰度方式渲染图像。因此,如果您的图像是完全不透明的,那么无论源图像是什么颜色,它都将始终渲染为黑色,但如果您的图像是透明的,它将渲染一些灰色阴影


为了将其渲染为完全白色或颜色,需要创建自定义uibarbuttonite。有关详细信息,请参见

能否提供正在发生的情况的图片?您确定您的图像格式正确,并且由于某种原因没有反转吗?尝试另一种颜色,看看发生了什么。看看这里:这是UIButton中的相同图像。向上的在导航控制器上,向下的在uitoolbar上。