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?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- back button text does not change
相关文章
- 现在使用swift开发ios应用好还是swift?
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- Popover segue to static cell UITableView causes co
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.
Obj - c
Swift 4
For Button Image
For Button Title
You can do this:
The button looks enabled but it will not receive any touch event.
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.
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 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.