In the application that I create, there are many custom UIButtons lying on top of fairly accurately laid out images. Buttonish, manage images and shortcuts and what you have, but with an explicit UIButton custom style sitting on top of it to handle the tap.
My client said yesterday: "I want this to be emphasized when you click it." Never mind that he immediately pushes a new look at the uinavigationcontroller ... he did not blink, and so he was embarrassed. Oy.
Here is what I did to solve it. I don't like this, but this is what I did:
I have subclassed UIButton (naming it FlashingUIButton).
For some reason, I couldn’t just set it up with the highlighted image background in control mode. It seemed that it never fell into a state of "stressed". I don’t know why this is so.
So I wrote:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self setBackgroundImage:[UIImage imageNamed:@"grey_screen"] forState:UIControlStateNormal]; [self performSelector:@selector(resetImage) withObject:nil afterDelay:0.2]; [super touchesBegan:touches withEvent:event]; } -(void)resetImage { [self setBackgroundImage:nil forState:UIControlStateNormal]; }
This happily lays my grey_screen.png (30% opaque black box) above the button when it taps and replaces it with a happy void .2 seconds later.
This is good, but it means that I need to go through all my numerous tips and change all my buttons from UIButtons to FlashingUIButtons. That is not the end of the world, but I would really hope to name it as the UIButton category and hit all the birds with one stone.
Any suggestions for a better approach than this?
source share