【问题标题】:UIBarButtonItem setTintColor doesn't work for dark colorsUIBarButtonItem setTintColor 不适用于深色
【发布时间】:2012-01-09 23:40:03
【问题描述】:

我正在设置UIBarButtonItemtintColor。只要颜色是明亮的颜色,这就会起作用,只要我尝试将其设置为 darkGrayColor 什么都没有发生,实际上它会将色调更改为白色!但是,如果我将颜色更改为redColor,那么它就可以工作了……这是怎么回事?

UIBarButtonItem *penButton = [_toolBar.items objectAtIndex:3];
UIBarButtonItem *crossButton = [_toolBar.items objectAtIndex:4];

//This actually sets the tint to white not gray, which is odd?
[penButton setTintColor:[UIColor darkGrayColor]]; 
[crossButton setTintColor:[UIColor redColor]]; //Red is fine, as is green etc

【问题讨论】:

  • 您是否尝试过提供自定义颜色(RGB 值)并检查结果?
  • 好主意,但这似乎也不起作用,我会用结果更新问题
  • 设置色调颜色无效,但设置新的 alpha 有效!!
  • 设置整个 UIBarButtonItem 或随 tint 颜色提供的颜色值的新 alpha?无论如何,我建议您创建一个错误报告,因为这些限制似乎没有记录在案。请随时通知我们。

标签: iphone objective-c uikit uibarbuttonitem


【解决方案1】:

[UIColor redColor][UIColor darkGrayColor] 的区别在于前者使用RGB 值设置,后者使用灰度设置,而UIBarButtonItem 以某种方式忽略了灰度。你可以通过比较来检验这个理论:

[penButton setTintColor:[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0]]; 

[penButton setTintColor:[UIColor colorWithWhite:0.5 alpha:1.0]]; 

如果前者符合预期,而后者则不然,那么问题确实出在灰度上。否则我不知道是什么导致了这种行为。

【讨论】:

  • 我试过了,它仍然是白色的,将 alpha 设置为 0.2 得到了我想要的效果,但显然没有回答原始问题!
  • @Chris 很有趣。你的意思是你设置UIColorUIBarButtonItem的alpha?
  • 我的意思是 UIColor 的 alpha 根据你的例子!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-18
  • 1970-01-01
  • 2021-06-04
相关资源
最近更新 更多