【问题标题】:How should I accomplish "setTintColor forState" (which does not exsist)?我应该如何完成“setTintColor forState”(不存在)?
【发布时间】:2025-12-26 08:45:17
【问题描述】:

在我的应用委托中,我有这个:

UIColor* color = [UIColor colorWithRed:36/255.0f green:38/255.0f blue:56/255.0f alpha:1.0f];
[[UIBarButtonItem appearance] setTintColor:color];

我想为按下状态设置另一种颜色。

如何在不使用背景图片的情况下实现这一点?

【问题讨论】:

标签: ios xcode uiappearance


【解决方案1】:

UIBarButtonItem 没有不同的状态。但是UIButton 可以。因此,您可能希望在导航栏或工具栏中放置一个普通 Button,然后为每个状态使用不同的背景图像,这对于 UIButton 是可能的,或者如果您只想更改突出显示的色调,则使用 Highlight Tint 属性状态。

如果您为不同的状态使用图像,那么您可以为这些状态定义图像:

  • 默认
  • 突出显示
  • 已选择
  • 已禁用

查看此 SO 帖子:UIButton as UINavigationbar button

【讨论】:

    最近更新 更多