Clay
Clay

Reputation: 635

UIButton stay selected after Touch

I'd like to have a UIButton stay in the Selected state after touching it. I've added the code to set the selected state during the TouchUpInside event; however, after a quick tap there's a slight "blink" between states. I have a few strategies for doing this using an UImageView and adding a UITapGestureRecognize, but there has to be an easier way.

Upvotes: 3

Views: 2682

Answers (5)

Clay
Clay

Reputation: 635

Thanks for the great answers. Rather than dealing with UIButton, I ended up using a UIImageView and set the highlighted state in an animation block based on a tap gesture. It made it much easier to accomplish a pressed state rather than trying to account for UIButton gesture handling.

Upvotes: 0

Manoj Thomas
Manoj Thomas

Reputation: 56

Create a UIView looks similar to the button. Just add the button as subview of a UIView and also add button's title(UILabel) as subview of the same UIView. On pressing the button, change the properties of the UIView and UILabel as to make it look like pressed button so that the view can stay as pressed state until you change those properties again.

Hope this helps.

Upvotes: 1

Gopal R
Gopal R

Reputation: 742

This is just off the top of my head

A UIBUtton has four states - Normal, Highlighted, Selected, Disabled I think the 'blink' you are noticing is due to the highlighted state. The button probably goes through the highlighted state when tapped making it 'blink'

Try setting the highlighted state properties the same as the selected state.

Upvotes: 2

Ravindhiran
Ravindhiran

Reputation: 5384

try this,

[button sendActionsForControlEvents:UIControlEventTouchUpInside];
[button setSelected:YES];

Upvotes: 1

matt
matt

Reputation: 536028

The reason for the flash is that Touch Up Inside is too late; the user's finger is already up, by definition. Perhaps you should consider implementing an action event for Touch Down Inside instead (or in addition).

Another possibility might be to use a UISegmentedControl with one segment and momentary set to NO.

Upvotes: 4

Related Questions