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 状态

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容