UIButtonTypeInfoLight 在哪里?

发布于 2025-01-02 22:50:27 字数 863 浏览 2 评论 0原文

我正在按钮栏项目的标识符列表中寻找 UIButtonTypeInfoLight 选项,但没有看到它。那么,有两个问题。

  1. 它是否只是丢失了,我必须用代码手动创建它?我想知道为什么他们会省略它。

  2. 假设我必须手动创建按钮,以从中调用转场,我是否需要手动执行转场而不是使用故事板?

我假设我会从我的按钮调用的方法中执行此操作 [self PerformSegueWithIdentifier:@"ShowChecklist" sender:nil];

创建我的按钮的代码是

UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self action:@selector(infoButtonAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *modalButton = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
[self.navigationItem setRightBarButtonItem:modalButton animated:YES];

那么,这是一种常见模式吗?我在做一些奇怪和不标准的事情吗?在我看来,如果我的 BarButton 只是一个显示“信息”的自定义按钮,我可以创建它并将其全部连接到故事板中......但对于这个,我必须在代码中完成所有操作。

菜单:

I'm looking for the UIButtonTypeInfoLight choice in the identifier list for button bar items, and I'm not seeing it. So, two questions.

  1. Is it just missing and I'll have to create it manually, in code? I'm wondering why they would omit it.

  2. Assuming I do have to create the button manually, to call a segue from it,do I need to manually perform the segue rather than using the storyboard?

I'm assuming I'd do this [self performSegueWithIdentifier:@"ShowChecklist" sender:nil]; from the method that my button is calling.

The code that created my button is

UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self action:@selector(infoButtonAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *modalButton = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
[self.navigationItem setRightBarButtonItem:modalButton animated:YES];

So, Is this a common pattern? Am I doing something weird and nonstandard? It just seems to me to be weird that if my BarButton were just a custom button that said "info" I could create it and wire it up all in the Storyboard... but for this one, I have to doit all in code.

Th menu:

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

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

发布评论

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

评论(1

云淡风轻 2025-01-09 22:50:27

UIButtonTypeInfoLight 是一个 UIButton。按钮栏项目是 UIBarButtonItems。他们彼此没有任何关系。你只是混淆了苹果和橙子。

但是,UIBarButtonItem 可以包含 UIButton。 (这仅仅是因为它可以包含任何 UIView。)因此,将 UIButton 拖到工具栏中。您得到的是一个 UIBarButtonItem 包含一个 UIButton。如果双击 UIBarButtonItem,您将获得 UIButton。现在您可以设置按钮的类型。

UIButtonTypeInfoLight is a UIButton. Button bar items are UIBarButtonItems. They have nothing to do with each other. You're just confusing apples and oranges.

However, a UIBarButtonItem can contain a UIButton. (That's merely by virtue of the fact that it can contain any UIView.) So drag a UIButton into a toolbar. What you get is a UIBarButtonItem containing a UIButton. If you double-click the UIBarButtonItem, you get the UIButton. Now you can set the button's type.

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