【问题标题】:Tint UIButton when tapped?点击时为 UIButton 着色?
【发布时间】:2012-10-26 16:05:06
【问题描述】:

有没有办法使用图像在 UIButton 上设置色调颜色,所以当手指在按钮上时,色调会覆盖图像?在点击按钮时有这样的高亮效果会很好,而不是使按钮图像的数量增加一倍。

【问题讨论】:

  • 我认为iOS上的一般原则是更喜欢使用双图像,所以所有工作都在桌面上完成。您正在针对谷物进行优化。

标签: ios cocoa-touch


【解决方案1】:

如果您只是想减少项目中的资产数量,您可能会创建UIButton 的子类并覆盖setImage:forState:

- (void)setImage:(UIImage *)image forState:(UIControlState)state;
{
  [super setImage:image forState:state];

  UIImage *processImage = // Process the image to add tint
  [self setHighlightImage:processedImage forState:state];
}

【讨论】:

    【解决方案2】:

    您可以使用 setHighlightImage:forState 或 setImage:forState: 使用状态 UIControlStateHighlighted

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-06
      • 2015-02-02
      相关资源
      最近更新 更多