What's the difference between UIControlStateHighlighted and UIControlStateSelected?

后端 未结 4 1391
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 19:21

I am trying to set a state for UIButton.

But i don\'t know the difference between the UIControlStateHighlighted and UIControlStateSelected.

相关标签:
4条回答
  • 2021-02-05 19:33
    • UIControlStateHighlighted = it highlights the button with some flash(in button background) when the user taps.

    • UIControlStateSelected = it highlights nothing to that button.

    0 讨论(0)
  • 2021-02-05 19:38

    Highlighted is typically applied transiently when the control is being touched, selected is a more permanent state. Imagine a checkbox type button which dimmed while it was being touched - dimming is highlighted, ticked is selected, unticked is unselected.

    Typically you'd never set highlighted status manually as the system will be setting/unsettling it in response to touches, whereas selected is safer. This particularly applies to buttons.

    0 讨论(0)
  • 2021-02-05 19:42

    They can mean whatever you want them to, but in general they mean the following:

    Highlighted = The user is currently interacting with something that will change once they stop interacting (e.g. holding down a button)

    Selected = The item is current the active item in a group (e.g. The selected item in a segmented control). This can only be achieved by setting it programmatically.

    0 讨论(0)
  • 2021-02-05 19:55

    From the official doc:

    UIControlStateHighlighted Highlighted state of a control. A control enters this state when a touch enters and exits during tracking and when there is a touch up event. You can retrieve and set this value through the highlighted property.

    UIControlStateSelected Selected state of a control. For many controls, this state has no effect on behavior or appearance. But other subclasses (for example, the UISegmentedControl class) may have different appearance depending on their selected state. You can retrieve and set this value through the selected property.

    Your button get highlighted in reaction of a touch event. It could then be on a selected state within a group (for segmented control).

    0 讨论(0)
提交回复
热议问题