Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 341
Jamal Zafar Avatar asked Jul 24 '12 10:07

Jamal Zafar


People also ask

What is the highlighted 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.

How do you highlight a button in Swift?

In storyboard choose the UIButton you want to change. In the identity inspector in the right corner there is a filed named "class" there type "HighlightedButton" and press enter. Now your button will change color to red when it is highlighted and back to green when you release the button.

What is UIButton Swift?

A control that executes your custom code in response to user interactions.


2 Answers

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.

like image 74
clozach Avatar answered Oct 06 '22 11:10

clozach


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.

like image 45
holex Avatar answered Oct 06 '22 11:10

holex