使用 iOS 5 外观 API 的 UIBarButtonItemStyleDone 背景图像

发布于 2024-12-17 08:34:54 字数 169 浏览 2 评论 0原文

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

How can I provide a visually distinct bar button item background image for bar buttons with the UIBarButtonItemStyleDone style and the editing state of the Edit/Done button? None of the documented UIControlState values in the UIBarButtonItem appearance proxy's setBackgroundImage:forState:barMetrics: seem to do the trick.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人生戏 2024-12-24 08:34:54

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

- (void)viewDidLoad
{
    [super viewDidLoad];

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

I'm not sure why this was never answered but if you are still looking then simply create a property for a BarButtonItem in your .h, assign it in IB, then set the background property of that barButtonItem. Works fine for me and never "changes back to default appearance".

- (void)viewDidLoad
{
    [super viewDidLoad];

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

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

自定义 UIBarButtonItem“完成”样式和“普通”样式" 使用 UIAppearance 单独设置样式

I have just found and posted a possible solution to this problem.
You can 'inject' custom styles using a UIBarButtonItem category:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文