iphone - 如何在没有 UIToolBar 的情况下使用 UIBarButtonItem 样式

发布于 2024-09-29 03:25:46 字数 171 浏览 2 评论 0原文

我可以在我的视图中显示黑色风格的 UIBarButtonItem 而没有下面的 UIToolBar 吗?

UIToolBar 总是有一种边框的东西,我希望系统 UIBarButtonItem 是黑色的,就像黑色标准取消按钮一样,但 UIToolBar 不是,

我该怎么办?

谢谢

Can I show a black style UIBarButtonItem in my view without the underneath UIToolBar?

The UIToolBar always has a kind of border thing, I want the system UIBarButtonItem in black just like a black standard cancel button, but not the UIToolBar

How can I do it?

Thanks

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

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

发布评论

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

评论(2

绝不服输 2024-10-06 03:25:46

有一个厚颜无耻的黑客可以帮助你解决这个问题。

您想要使用样式设置为 UISegmentedControlStyleBar 的 UISegmentedControl 并且仅使用一项。您还需要将 setMomentary 设置为 yes - 使其表现得像一个按钮:

UISegmentedControl *myCustomButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Hello",nil]];
[myCustomButton setSegmentedControlStyle:UISegmentedControlStyleBar];
[myCustomButton setTintColor:[UIColor blackColor]];
[myCustomButton setMomentary:YES];
[self.view addSubview:myCustomButton];

这将为您提供一个看起来像 UIBarButtonItem 的按钮,您可以将其添加到普通视图中,就像它是一个按钮一样。您也可以添加目标和操作。 :)

这就是你得到的:像这样的:

alt text

there is a cheeky hack that will help you with this.

you want to use a UISegmentedControl with style set to UISegmentedControlStyleBar and only one item. You also need to setMomentary to yes - to make it behave like a button:

UISegmentedControl *myCustomButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Hello",nil]];
[myCustomButton setSegmentedControlStyle:UISegmentedControlStyleBar];
[myCustomButton setTintColor:[UIColor blackColor]];
[myCustomButton setMomentary:YES];
[self.view addSubview:myCustomButton];

This will give you a button that looks like a UIBarButtonItem that you can add to your normal view as if it were a button. You can add a target and an action as well. :)

This is what you get: something like this:

alt text

酒几许 2024-10-06 03:25:46

我还没有完全做过类似的事情,但我建议您可以以某种方式将除 UIBarButtonItem 之外的所有 UIToolBar 的子视图 alpha 设置为零。只需让 UIBarButtonItem 可见即可。

UIToolBar继承自UIView,所以我的第一个尝试是将其backgroundColor设置为clearColor。

I haven't exactly done anything like that, but I suggest you could somehow set all the UIToolBar's subviews alpha to zero except for the UIBarButtonItem . Just leave the UIBarButtonItem visible.

UIToolBar inherits from UIView, so my first try would be to set its backgroundColor to clearColor.

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