NavigationController UIToolbar 更改项目
我想通过隐藏工具栏、更改项目(按钮、固定空间等)并再次显示来更改 UIToolbar
中的项目。
目前,我的 UIToolbar
上有一个按钮,按下该按钮时,会通过调用 [[self navigationController]setToolbarHidden:YESanimated:YES];
隐藏工具栏。
我该如何设置这些项目?是否可以使用界面生成器或者我需要对它们进行硬编码?
I want to change the items in my UIToolbar
by hiding the toolbar, changing the items (button, fixed space, etc), and revealing it again.
I currently have a button on my UIToolbar
that, when pressed, hides the toolbar by calling [[self navigationController]setToolbarHidden:YES animated:YES];
.
How can I set these items? Is it possible using interface builder or do I need to hard-code them in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是非标准行为,但应该是可行的。您可能会考虑创建一个淡入的不同工具栏,而不是删除现有工具栏并添加新按钮。这将使编码/调试变得更容易。一般来说,它只需要减少“混乱”。
要实现所需的行为,您可以执行以下操作:
此示例假设您已经将其他工具栏加载到
newToolbar
属性中。如果您需要进一步帮助或任何解释,请告诉我。This is non-standard behavior, but should be doable. You might consider instead of removing and adding new buttons to the existing toolbar, to instead create a different toolbar that gets faded in instead. This would make things easier to code/debug. In general, it just requires less "mess."
To achieve the desired behavior, you could do something like:
This example assumes that you have already loaded your other toolbar into the
newToolbar
property. Let me know if you need further assistance or any explanation.您可以通过这种方式为工具栏设置新项目:
它还会为更改设置动画,因此您可能不需要再次隐藏和显示它,这通常不是一个好的 UI 实践。
You can set new items for the toolbar this way:
It will also animate the change so you may not need to hide and show it again, which is not a good UI practice in general.
有点奇怪......这有点hacky,但应该完全没问题:
A bit of an odd one... this is a bit hacky but should be perfectly fine: