ios - Can I use custom values of UIControlState for my own control? -


Is there a way to set a custom state - one of the current UIControlState values - - UIControl ?

In the UIControlSate enum, there are 16 bits used for custom control states:

  UIControlStateApplication = 0x00FF0000, / / Additional flag available for use  

The problem is that UIControl 's state is the property readable .

< P> You can use custom states in subclass of UIControl.

  • Create a variable called customstate in which you will manage your custom states.
  • If you need to set a state, then against the variable against the variable, and call [Self-State Update] .
  • property to return property [super state] bitwise or your customstate
  • Override override
  • enabled , selected and highlighted setters so that they [auto-state updates] To call. To answer the changes that happen in the state, use stateWasUpdated with logic
  • This will allow you to respond to any change in the state

In the header:

  #define kUIControlStateCustomState (1 << <16) @interface MyControl: UIControl {UIControlState CustomState; }  

In implementation:

  @implementation MyControl - (zero) setCustomState {customState | = KUIControlStateCustomState; [Including the state of independence]; } - (zero) unsetCustomState {customstate & amp; = ~ KUIControlStateCustomState; [Including the state of independence]; } - (UIControlState) state {return [super state] | CustomState; } - (zero) set selected: (BOOL) Newly selected {[Selected from super set: newly selected]; [Including the state of independence]; } - Highlighted (zero) set: (BOOL) New highlighted [[Super set highlights: New highlighted]; [Including the state of independence]; } - (zero) set Translated: (BOOL) Newer spoken {{Super-set: Enabled;]; [Including the state of independence]; } - (zero) state-of-the-art update {// add your custom code here to answer the change in state} @end  

Comments