[英]How to Hide the UIbarbutton on navigation bar
hi i have created a bar button which displays Done when the editing of the text view starts. 您好我创建了一个条形按钮,在编辑文本视图开始时显示完成。 what actually i need that when i press the done button then the the editable property of textview will become false and the done button hides.
实际上我需要的是当我按下完成按钮然后textview的可编辑属性将变为false并且完成按钮隐藏。
i am done with the first part but how to hide the bar button? 我完成了第一部分,但如何隐藏栏按钮?
please help.. 请帮忙..
@ christo16的解决方案对我来说并不适用,但它引导我做到了这个:
[self.navigationItem.rightBarButtonItem setEnabled:NO];
You can disable it (it becomes dim): 你可以禁用它(它变得昏暗):
//assuming it's the right one
[[[myNavigationBar topItem]rightBarButtonItem]setEnabled: NO];
I think to hide it, you actually have to set it nil. 我想隐藏它,你实际上必须把它设置为零。 Then recreate it when you need it.
然后在需要时重新创建它。
[[myNavigationBar topItem]setRightBarButtonItem:nil animated:NO];
Setting it enabled/disabled will not achieve the same as isHidden given that it will still be visible (just slightly dimmer). 将其设置为启用/禁用将不会与isHidden相同,因为它仍然可见(略微调暗)。 If you set the bar button item to nil, then you cannot easily toggle it back on again.
如果将条形按钮项设置为nil,则无法再轻松将其重新打开。
Instead, you can toggle visibility on/off by using tint color...here is a Swift implmentation. 相反,您可以通过使用色调颜色来打开/关闭可见性...这里是一个Swift实现。
Toggle off (simulating isHidden
true): 切换关闭(模拟
isHidden
true):
self.navigationItem.rightBarButtonItem.tintColor = UIColor.clear
self.navigationItem.rightBarButtonItem.isEnabled = false
And back on (simulating isHidden
false): 然后重新开始(模拟
isHidden
false):
self.navigationItem.rightBarButtonItem.tintColor = UIColor.white // or nil
self.navigationItem.rightBarButtonItem.isEnabled = true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.