简体   繁体   English

如何隐藏导航栏上的UIbar按钮

[英]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];

If it was just a UIButton, I'd say you can do something like this: 如果它只是一个UIButton,我会说你可以这样做:

myButton.hidden = YES;

But if it's a UIBarButtonItem, you could try the solution here . 但如果它是一个UIBarButtonItem,你可以在这里尝试解决方案。 Let us know if it works! 如果有效,请告诉我们!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM