Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can make use of the custom states in a subclass of UIControl. </p> <ul> <li>Create a variable called <code>customState</code> in which you will manage your custom states. </li> <li>If you need to set a state, do your flag operations against this variable, and call <code>[self stateWasUpdated]</code>. </li> <li>Override the <code>state</code> property to return <code>[super state]</code> bitwise OR'd against your <code>customState</code></li> <li>Override the <code>enabled</code>, <code>selected</code> and <code>highlighted</code> setters so that they call <code>[self stateWasUpdated]</code>. This will allow you to respond to any changes in state, not just changes to <code>customState</code> </li> <li>Implement <code>stateWasUpdated</code> with logic to respond to changes in state</li> </ul> <p>In the header:</p> <pre><code>#define kUIControlStateCustomState (1 &lt;&lt; 16) @interface MyControl : UIControl { UIControlState customState; } </code></pre> <p>In the implementation:</p> <pre><code>@implementation MyControl -(void)setCustomState { customState |= kUIControlStateCustomState; [self stateWasUpdated]; } -(void)unsetCustomState { customState &amp;= ~kUIControlStateCustomState; [self stateWasUpdated]; } - (UIControlState)state { return [super state] | customState; } - (void)setSelected:(BOOL)newSelected { [super setSelected:newSelected]; [self stateWasUpdated]; } - (void)setHighlighted:(BOOL)newHighlighted { [super setHighlighted:newHighlighted]; [self stateWasUpdated]; } - (void)setEnabled:(BOOL)newEnabled { [super setEnabled:newEnabled]; [self stateWasUpdated]; } - (void)stateWasUpdated { // Add your custom code here to respond to the change in state } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload