How to programmatically highlight a UIButton?

I had many users who complained that the small β€œI” button on the iPhone was hard to press. Okay, quite simple - I just inserted a thick invisible button for it, which cannot be missed even with the most inaccurate finger touches, and when you touch it, it performs the infoButtonAction action.

The fact is that I would like to blink the information button on my own for about 25 seconds, just to give a visual type of feedback "this is what happens." I mean, I already assume that you wanted to press the "i" button, so I just treat it as if you REALLY pressed.

I tried this, but this does not work:

UIImage* normalImage = [_infoButton imageForState:UIControlStateNormal]; UIImage* highlighted = [_infoButton imageForState:UIControlStateHighlighted]; _infoButton.highlighted = YES; // flash the button [_infoButton setImage:highlighted forState:UIControlStateNormal]; [_infoButton setNeedsDisplay]; //* FIXME: No flash?! [(AppDelegate*)[[UIApplication sharedApplication] delegate] infoTap]; // do the info action _infoButton.highlighted = NO; [_infoButton setImage:normalImage forState:UIControlStateNormal]; [_infoButton setNeedsDisplay]; 

Any ideas on how to get the behavior I want?

(I am also open to alternative ideas about user feedback, but still curious how I would do this. Imagine instead that I have a β€œgame” / rally where you press the OK button and blinks cancellation, "and vice versa, or something just as stupid.)

+4
source share
3 answers

The problem is that you mark your button as necessary for display (the -setNeedsDisplay call -setNeedsDisplay not required, the button calls it internally), but then it never allows the loop to display a new image.

In Cocoa, you can use something like -performClick: but it is not available on the iPhone.

Instead, I suggest you experiment with calling -setSelected: or -setHighlighted: with a delay between them.

+1
source

The β€œi” button should be 44 Γ— 44 (standard Apple finger size), which can be done in Interface Builder.

For some animations, I suggest looking at Core Animation.

+4
source

I don’t know exactly what happens in your infotap method, but there seems to be nothing that could cause a big delay between your first setImage: call and the second. I assume that everything happens faster than the eye can see. I suggest looking at NSTimer to try to set a certain delay there.

0
source

All Articles