What is the difference between Highlighted and Selected UIButton's State?

Objective CUibutton

Objective C Problem Overview


Can anyone tell me What is the difference between Highlighted and Selected state of a UIButton?

Objective C Solutions


Solution 1 - Objective C

The answers from 2012 aren't incorrect, but some might find the explanation in the UIControl docs to be…anemic. I personally find this explanation from the Collection View Programming Guide for iOS to be more helpful:

> There is a subtle but important distinction between a cell’s highlighted state and its selected state. The highlighted state is a transitional state that you can use to apply visible highlights to the cell while the user’s finger is still touching the device. This state is set to YES only while the collection view is tracking touch events over the cell. When touch events stop, the highlighted state returns to the value NO. By contrast, the selected state changes only after a series of touch events has ended—specifically, when those touch events indicated that the user tried to select the cell. > > […snip…] > > enter image description here

Although this documentation is specifically for collection view cells, the explanation holds pretty well across the Cocoa Touch frameworks.

Solution 2 - Objective C

According to the documentation:

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.

and

Selected state of a control. For many controls, this state has no effect on behaviour or appearance. But other subclasses may have different appearance depending on their selected state.

this is the pure difference between the states.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJamal ZafarView Question on Stackoverflow
Solution 1 - Objective CclozachView Answer on Stackoverflow
Solution 2 - Objective CholexView Answer on Stackoverflow