UIButtonTypeInfoLight 在哪里?
我正在按钮栏项目的标识符列表中寻找 UIButtonTypeInfoLight 选项,但没有看到它。那么,有两个问题。
它是否只是丢失了,我必须用代码手动创建它?我想知道为什么他们会省略它。
假设我必须手动创建按钮,以从中调用转场,我是否需要手动执行转场而不是使用故事板?
我假设我会从我的按钮调用的方法中执行此操作 [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.
Is it just missing and I'll have to create it manually, in code? I'm wondering why they would omit it.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.