IPhone iOS 4 UIButton toggle highlighted state on and off

ios4iphoneuibutton

I got a UIButton with style "Info Dark" set up in interface builder in my iPhone 4 app. One of the properties of the button is "Highlighted", which displays a white highlight around the button.

I would like to toggle this white highlight on and off, indicating if the button function is active or not.

The button is linked for "Touch up inside" event in the interface builder with this callback:

infoButton.highlighted = !infoButton.highlighted;

After the first touch, the highlight disappears and does not toggle as I expect it to. What else do I need to do to make the highlight toggle and display the state of the button?

Thank you!

Update:
When loaded from the interface builder, the button stays highlighted, even as the view appears/disappears. What causes this to happen is the "shows touch on highlight" interface builder property. If I assign the code above to another button, the info button highlights on and off as expected. However, the touches of the info button itself interfere with the above code, causing the button to lose the "touch" highlight

Update 2: I added another info button, directly below the first info button, in the interface builder and made it glow permanently. To create the appearance of the toggle, I hide and unhide the glowInfoButton below the real one. This works as expected:

    infoButton.highlighted = NO;
    glowInfoButton.highlighted = YES;
    glowInfoButton.enabled = NO;
    glowInfoButton.hidden = YES;

- (IBAction)toggleInfoMode:(id)sender {
//    infoButton.selected = !infoButton.selected;
    glowInfoButton.hidden = !glowInfoButton.hidden;
 }

Best Answer

The Highlighted image is what displays when the UIButton is being pressed, and is controlled within the UIButton itself.

You're looking for the Selected property. You can set a Selected Image in IB, and then put a infoButton.selected = !infoButton.isSelected; in your TouchUpInside callback.