UIControlState

转自知乎用户 Jimmy Zhang,イレギュラー エンジニア 在知乎上的回答

  • UIControlStateNormal
    The normal, or default state of a control—that is, enabled but neither selected nor highlighted.

  • UIControlStateHighlighted
    Highlighted state of a control. A control becomes highlighted when a touch event enters the control’s bounds, and it loses that highlight when there is a touch-up event or when the touch event exits the control’s bounds. You can retrieve and set this value through the highlighted property.

  • UIControlStateDisabled
    Disabled state of a control. User interactions with disabled control have no effect and the control draws itself with a dimmed appearance to reflect that it is disabled. You can retrieve and set this value through the enabled property.
    可以通过enabled属性来设置该值

  • UIControlStateSelected
    Selected state of a control. For many controls, this state has no effect on behavior or appearance. Some subclasses, like the UISegmentedControl class, use this state to change their appearance. You can retrieve and set this value through the selected property.

  • UIControlStateFocused
    Focused state of a control. In focus-based navigation systems, a control enters this state when it receives the focus. A focused control changes its appearance to indicate that it has focus, and this appearance differs from the appearance of the control when it is highlighted or selected. Further interactions with the control can result in it also becoming highlighted or selected.

  • UIControlStateApplication
    Additional control-state flags available for application use.

  • UIControlStateReserved
    Control-state flags reserved for internal framework use.

基本的 State 变化过程如下

1.什么都没干的时候:Normal

2.当你的手指按下去,还没放的时候:Highlighted

3.当手指放开的时候:如果这个 UIControl 有 Selected 状态的话,就会变成: Selected

再重复上述过程一次,就会从 Selected->Highlighted-> Normal

普通的 UIButton 有 Normal , Highlighted , Disabled , Selected 状态

你可能感兴趣的:(UIControlState)