如何制作这样的 UIBarButtonItem

发布于 2024-11-14 12:10:46 字数 135 浏览 4 评论 0 原文

我怎样才能制作这样的 UIBarButtonItem: 在此处输入图像描述

我在 SystemItem 值中找不到它。

谢谢

How can I make a UIBarButtonItem like this:
enter image description here

I can't find it in the SystemItem values.

Thanks

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

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

发布评论

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

评论(3

小红帽 2024-11-21 12:10:46

您称为信息按钮的图像按钮。它是一个系统按钮,

使用下面的方法将其作为您的 rightBarButtonItem

UIButton* myInfoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
[myInfoButton addTarget:self action:@selector(InfoButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myInfoButton];

这里是 UIButtonType

The Image button which you have called info button.It's an system button,

Use below to get it as your rightBarButtonItem

UIButton* myInfoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
[myInfoButton addTarget:self action:@selector(InfoButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myInfoButton];

Here is the documentation link to UIButtonType

青衫负雪 2024-11-21 12:10:46

这可能使用类似的东西:

[[UIBarButtonItem alloc] initWithImage:@"info.png" style:UIBarButtonItemStyleBordered target:nil action:nil]

我尝试过:

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeInfoLight]];
item.style = UIBarButtonItemStyleBordered;

但似乎使用自定义视图时,边框样式不会被应用。

That's probably using something like:

[[UIBarButtonItem alloc] initWithImage:@"info.png" style:UIBarButtonItemStyleBordered target:nil action:nil]

I tried with:

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeInfoLight]];
item.style = UIBarButtonItemStyleBordered;

but it seems like with a custom view the bordered style doesn't get applied.

七禾 2024-11-21 12:10:46

@Jhaliya 的快速复制粘贴答案的 Swift 版本:

let infoButton = UIButton(type: .InfoLight)

infoButton.addTarget(self, action: "InfoButtonClicked:", forControlEvents: .TouchUpInside)

let infoBarButtonItem = UIBarButtonItem(customView: infoButton)

navigationItem.rightBarButtonItem = infoBarButtonItem

Swift's version of @Jhaliya's answer for quick copy-paste:

let infoButton = UIButton(type: .InfoLight)

infoButton.addTarget(self, action: "InfoButtonClicked:", forControlEvents: .TouchUpInside)

let infoBarButtonItem = UIBarButtonItem(customView: infoButton)

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