Search code examples
iphoneiosipaduibuttonibaction

How to make image behind invisible button look like it was pressed down?


Hi I have a couple of images that are covered by an invisible button. Is there a way that I can make it look like the images were pressed down when I press the invisible button? Thanks!


Solution

  • You can put the image directly onto the button, you dont need a seperate UIImageView.

    [button setBackgroundImage:image forState:UIControlStateNormal];
    [button setBackgroundImage:image forState:UIControlStateSelected];
    

    The are a few more UIControlState constants.

    Take a look at the docs:

    http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIButton_Class/UIButton/UIButton.html

    http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIControl_Class/Reference/Reference.html#//apple_ref/c/tdef/UIControlState