将 UIBarButtonSystemItemAdd 和 UIBarButtonSystemItemTrash 添加到导航项或 UISegmentedControl 的一侧
我想要一个 UIViewController
,它在标题右侧有一个“添加”和一个“垃圾箱”按钮,可以通过向导航项/栏添加两个 UIBarButtonItems
或添加将它们添加到 UISegmentedControl
中,然后将 SegmentedControl 添加到项目中。这可能吗?如果是,如何实现最好?
I'd like to have a UIViewController
which has an Add and a Trash button both right to the title, either by adding two UIBarButtonItems
to the navigation item/bar or by adding them to a UISegmentedControl
and then adding the SegmentedControl to the item. Is this possible? If yes, how is it achieved best?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过将多个按钮包装在
UIToolbar
中来向导航项添加多个按钮,示例代码< /a>.You can add multiple buttons to a navigation item by wrapping them in a
UIToolbar
, sample code.我也做过类似的事情。我通过创建一个包含两个 UIButton 的 UIView 子类,将两个 UIButton 添加到导航项/栏。然后,您可以执行以下操作:
您所要做的就是在
MyUIViewSubclass
中布局按钮,就可以了。此外,我还在自定义 init 命令中传递目标 ID,以便更轻松地定位视图中的按钮。因此,对于
MyUIViewSubclass
而不是initWithFrame
,我有这样的东西:I have done something similar. I've added two UIButtons to a navigation item/bar by creating a UIView subclass that has two UIButtons in it. You can then do something like this:
All you have to do is layout the buttons in
MyUIViewSubclass
and you're good.Also, I pass the ID of the target along in a customized init command to make for easier targeting of the buttons in the view. So for
MyUIViewSubclass
instead ofinitWithFrame
, I have something like this: