【问题标题】:UIBarButtonItem black instead of whiteUIBarButtonItem 黑色而不是白色
【发布时间】:2015-11-23 16:45:17
【问题描述】:

我有那个导航控制器,我正在通过代码添加 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)];

文本以白色正确显示。

这些图标没问题,因为我通过界面生成器使用它们并且它们显示正确。

【问题讨论】:

  • 你能提供一张正在发生的事情的图片吗?你确定你的图片格式正确并且没有被反转,出于某种原因吗? (尝试另一种颜色,看看会发生什么)
  • 看看这里:personales.upv.es/jorfermo/screenshot.jpg 这是 UIButton 中的同一张图片。上一个在导航控制器上,下一个在 uitoolbar 上。

标签: iphone image uibutton


【解决方案1】:

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

为了将其呈现为全白或颜色,您需要创建一个自定义UIBarButtonItem。详情见Can I have a UIBarButtonItem with a colored image?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    相关资源
    最近更新 更多