What's the difference between:
myBarButtonItem.enabled = NO;
and
myBarButtonItem.user开发者_如何学PythonInteractionEnabled = NO;
Does the button become gray each time?
From the apple documentation uibarbuttonitem does not posses userInteractionEnabled property.Since it inherits from UIBarItem Class Reference it also does not have userInteractionEnabled property.
And also if you use this line myBarButtonItem.userInteractionEnabled = NO;
your app will crash.
If you dont want your button to get pressed use this:-myBarButtonItem.enabled = NO;
Also see apple documentation.
For the regular Button:-
myButton.userInteractionEnabled = NO; will cause no effect in your image image and you can not press it also.
myButton.enabled = NO; will cause the shadow to come on your button image and you can not press it also.
I read through the documentation, and here are my findings.
UIButton
inherits from UIControl
the boolean property enabled
A Boolean value that determines whether the receiver is enabled.
Specify YES to make the control enabled; otherwise, specify NO to make it disabled. The default value is YES. If the enabled state is NO, the control ignores touch events and subclasses may draw differently.
UIControl
inherits from UIView
the boolean property userInteractionEnabled
:
A Boolean value that determines whether user events are ignored and removed from the event queue.
When set to NO, user events—such as touch and keyboard—intended for the view are ignored and removed from the event queue. When set to YES, events are delivered to the view normally. The default value is YES.
From this I conclude
button.userInteractionEnabled = NO
means the button looks normal but doesn't respond to touches (from theUIView
inheritance).button.enabled = NO
means the button is grayed out and doesn't respond to touches (from theUIControl
inheritance).
UIBarButtonItem
doesn't have a property called userInteractionEnabled
, only UIView
and it's subclasses have that property.
So, in short,
myBarButtonItem.userInteractionEnabled = NO;
wouldn't grey out the button, it would crash your program.
Setting the enabled
property to NO
, however, will grey out the button.
精彩评论