【问题标题】:UIBarButtonItemStyleDone background image using the iOS 5 appearance APIUIBarButtonItemStyleDone 使用 iOS 5 外观 API 的背景图片
【发布时间】:2012-01-02 21:39:51
【问题描述】:

如何为具有 UIBarButtonItemStyleDone 样式和编辑/完成按钮的编辑状态的条形按钮提供视觉上不同的条形按钮项背景图像? UIBarButtonItem 外观代理的 setBackgroundImage:forState:barMetrics: 中记录的 UIControlState 值似乎都不起作用。

【问题讨论】:

  • 您是在尝试专门自定义按钮的外观,还是希望所有 UIBarButtons 的背景都相似?
  • 我支持这个问题。只能为 [UIBarButtonItem 外观] 设置一个背景图像,但找不到如何为“完成”按钮设置不同的图像。如果我尝试设置完成按钮实例的背景图像,它会变回默认外观。我不明白。

标签: ios5 appearance uibarbuttonitemstyle


【解决方案1】:

我不确定为什么这个问题从未得到解答,但如果您仍在寻找,那么只需在 .h 中为 BarButtonItem 创建一个属性,在 IB 中分配它,然后设置该 barButtonItem 的背景属性。对我来说效果很好,并且永远不会“变回默认外观”。

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.barButton setBackgroundImage:[UIImage imageNamed:@"YOURIMAGE"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}

【讨论】:

    【解决方案2】:

    我刚刚找到并发布了解决此问题的可能方法。 您可以使用 UIBarButtonItem 类别“注入”自定义样式:

    Customizing UIBarButtonItem "Done" style and "Plain" style separately using UIAppearance

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-07
      • 1970-01-01
      • 2012-04-17
      • 1970-01-01
      • 2012-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多