如何使用无线电界面创建 UIBarButtonItems?
我有一个 UIToolbar,需要三个单选按钮,这意味着在这三个按钮中,一次只能按下一个按钮。该文档提到了在 width 属性的类参考定义中设置单选 UIBarButtonItems 的可能性:
如果该属性值为正, 组合图像的宽度和 标题是固定的。如果值为 0.0 或负数,该项目设置宽度 组合图像和标题的 合身。 如果 样式使用单选模式。默认 值为 0.0。
但是,我在 UIKit Framework Reference 中找到了“radio”,但找不到任何关于 radio 风格的 UIBarButtonItems 的提及。我知道我可以选择使用 TabBar 作为单选界面,但 TabBar 不太符合我的 UI 的目的(普通按钮 + 单选按钮)。我看到日历应用程序以单选样式(列表、日、月)使用 UIBarButtonItems,因此看起来这应该位于 API 中的某个位置并得到 HIG 的批准。这是隐藏在某个地方还是我必须使用自定义视图创建 UIBarButtonItems ?
I have a UIToolbar that needs three buttons in a radio style, meaning that of the three, only one button can be pushed at a time. The documentation makes reference to the possibility of setting up radio UIBarButtonItems in the class reference definition of the width property:
If this property value is positive,
the width of the combined image and
title are fixed. If the value is 0.0
or negative, the item sets the width
of the combined image and title to
fit. This property is ignored if the
style uses radio mode. The default
value is 0.0.
However, I did a find for "radio" in the UIKit Framework Reference and I can't find any mention of UIBarButtonItems in radio style. I know that I could alternatively use a TabBar for a radio interface, but a TabBar doesn't quite match the purpose of my UI (normal buttons + radio buttons). I see that the Calendar App uses UIBarButtonItems in a radio style (List, Day, Month), so it seems like this should be somewhere in the API and approved by the HIG. Is this hiding somewhere or would I have to create UIBarButtonItems with custom views?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UISegmentedControl 就是您想要的。它有点隐藏在 Interface Builder 中,因为它是工具栏之外的不同样式。
正常样式:
工具栏中的相同内容:
对于它的行为,您有两种选择:点击时短暂突出显示,或无线电风格的行为,这正是您想要的。您可以使用属性检查器中的“瞬时”复选框进行设置:
A UISegmentedControl is what you want. It's kind of hiding in Interface Builder, as it's a different style outside of a toolbar.
The normal style:
The same thing in a toolbar:
You have two options for its behavior: a momentary highlight when tapped, or a radio-style behavior, which is what you want. You can set this with the "Momentary" checkbox in the Attributes inspector:
您是否考虑过尝试 UISegmentedControl?您可以将其设置为一次仅“按下”其中一个片段。
Have you considered trying a UISegmentedControl? You can set it up so that only one of the segments is "pressed" at a time.
如果您需要在 objc 中实时执行此操作,
对我有用。代码在下面
我使用了这篇(不是我的)帖子中的一些代码 http://howtomakeiphoneapps.com/here-is-how-you-use-the-segmented-control-uisegmentedcontrol/129/
If you need to do this in objc in real time
worked for me. Code is below
I used some code from this (not mine) post http://howtomakeiphoneapps.com/here-is-how-you-use-the-segmented-control-uisegmentedcontrol/129/