如何在不禁用的情况下禁用用户触摸 UIbarbutton?
我的工具栏中有一个 UiBarButton 项目。我需要停用用户触摸交互 UiBarButton。它没有 setUserInteractionEnabled 属性。当我隐藏它时,没有适当的可见性。有人可以告诉我如何在不禁用 UIbarbutton 的情况下禁用它的用户触摸交互吗?
i have a UiBarButton item in my Toolbar.i need to deactivate the user touch interaction in
UiBarButton. there is no setUserInteractionEnabled property to it. when i am hiding it there is no proper visibility .can any one tell me that how can i disable user touch interaction of a UIbarbutton without disabling it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
要在 UIToolBar 中添加标题,请将 UIBarButtonItem 添加到工具栏,然后将其 customView 属性设置为 UILabel。然后,您可以设置标签的文本,并且不进行任何突出显示等。
To have a title in a UIToolBar, add a UIBarButtonItem to your toolbar and then set its customView property to a UILabel. You can then set the text of the label and not have any highlighting, etc.
您可以这样做:
按钮看起来已启用,但不会接收任何触摸事件。
You can do this:
The button looks enabled but it will not receive any touch event.
您始终可以这样做:
这将删除与该按钮关联的所有操作和目标。
You can always do:
That will remove all actions and targets associated with the button.
Obj - c
Swift 4
按钮图像
按钮标题
Obj - c
Swift 4
For Button Image
For Button Title
创建与您的按钮关联的自定义属性。
假设您的按钮触发以下操作:
创建一个实例变量,例如
BOOL InteractionEnabled;
并在 viewDidLoad 或其他 init 方法中将其设置为YES
当您需要禁用按钮时交互,只需将其设置为
NO
在按下按钮时触发的方法中,只需添加一个 if 条件检查即可查看
interactionEnabled
的状态,例如所以:这不会禁用该按钮,但是当您不希望用户与该按钮交互时,它会阻止用户与其交互。
Make a custom property associated with your button.
Let's say your button fires the action below:
Make an instance variable such as
BOOL interactionEnabled;
and in your viewDidLoad or other init method set it toYES
When you need to disable button interaction, simply set it to
NO
In your method that is fired when the button is pressed, just add an if-condition checking to see what the state of
interactionEnabled
is, like so:This won't disable the button, but it will prevent the user from interacting with it when you don't want them to.
您将自定义 UILabel 分配初始化为 UIBarbuttonItem (如何?请参阅此 帖子),没有文本,它应该足够大以覆盖您要禁用的 UIBarbuttonItem。这对我有用。
You alloc-init a custom UILabel as a UIBarbuttonItem (how? see this post) with no text and it should be large enough to cover the UIBarbuttonItem you want to disable. It worked for me.
您可以在这里找到答案。
在.h文件中:
在.m文件中:
在.h文件中创建UIBarButtonItem作为IBOutlet并在实现文件中访问,您可以使用UIBarButtonItem的问题 - “setEnabled”来启用或禁用它。
如果您需要更多帮助,请告诉我。
You can find your answer here.
In .h File:
In .m File:
Create the UIBarButtonItem as IBOutlet in .h file and access in the implementation file and you can use the problerty of UIBarButtonItem - "setEnabled" to make it enable or disable.
Let me know if you need more help.