uibutton controlstate image problem - iphone

i have a uibutton. im using two images for UIControlStateNormal and UIControlStateSelected. when i touch down the button it shows the UIControlStateSelected image for a split second. what is the reason?

I'm not sure i've got ur question correctly but try setting the image for UIControlStateHighlighted instead of UIControlStateSelected if you want the other image to be displayed as long as you keep the button pressed.
Reference: UIControl Documentiation says,
Note that the control can be in more than one state
In you case Selected and Highlighted. So UIControlStateNormal image is the default image used for highlighted state.
This is my best guess.
Good Luck,
Swapnil

Related

Highlight controls programmatically

I have many controls like, image views, labels (UIControls), which have I wish to show like a dual mode controls. i.e. Based on my data, I have to set them either with image 1 or image 2 (for a image view), similarly with the label. I tried accomplishing this using the highlighted state properties of image view and labels. For the image view, I gave one image reference for highlighted and another for normal.
however when I programmatically set the highlighted property to yes, they are not toggling between them. Is there something I'm missing?
From the documentation:
Highlighted state of a control. A control enters this state when a
touch enters and exits during tracking and when there is a touch up
event. You can retrieve and set this value through the highlighted
property.
So, you don't set the highlighted property. Try setSelected.
Have you seen this related topic: Highlighting a UIControl subclass?
Use selected state instead. I think highlighted state is a transient state.
Try this out:
if([imgeview isselected]){
[imageview setselected:NO];
}else{
[imageview setselected:YES];
}

iPhone UIButton provide different inset values for highlighted state

I want my titleLabel text move a little down on button tap (i.e. I want to give different inset values for highlighted and default states).
I have custom button background images and the button goes down in highlighted state image but the text on it stands at the same place so it gives a bad effect and looks like the text is seperated from button.
Is there any way to solve this?
Thanks in advance
The easiest way to do this is to put your text on the button's background image.
If you can't do that for some reason you can try to add IBAction on Button down and adjust button.titleLabel.frame.

UIButton sets dark when it is selected (I want to avoid this)

I'm developing an iOS 4 application.
I'm using a custom uibutton to make an image clickable. When user taps over the image, it will disappear.
It's not very pretty to see that the image gets black, then turns to its original color, and then disappear.
Is there a way to disable that effect?
You will need to set the property adjustsImageWhenHighlighted to NO:
[button setAdjustsImageWhenHighlighted:NO];
Alternatively you can set the same image for all controlStates of the button.
You need to set the property Shows Touch On Highlight to enabled.
Programmatically you can do that with:
[button setShowsTouchWhenHighlighted:YES];
Since it's a custom button, you get to specify the image you want to show when it's highlighted. Create the image you want to show in that situation.
If you are using interface builder just set the Highlighted and selected states to the same image as the default image.

Images & Buttons

I have assigned a button (holdCardOne) an image in the interface builder. What I want to do is change the image when a card is selected from a picker. I have the picker working and selecting the card but I need to change the image on the original selected button to resemble the selection.
Can I do this using code?
Does it matter I assigned the image in the interface builder or does it have to be all done by code?
You should be able to change the button image using the setImage:forState: method of the UIButton class. See the UIButton class reference for more info.
In terms of using the Interface Builder, it would be safe to set the initial image in that, but you'll need to handle things yourself from that point onwards. (e.g.: If a user can un-associate an image with a button, you'll need to set an appropriate image programatically as above.)
You can do it either in code or in the interface builder or both!
InterfaceBuilder lets you assign images for each button state (normal, highlighted, selected) -- so it could be as easy as assigning images for each state, and then simply changing the state in your code.
Alternatively, you can set the image directly, simply by saying:
[myButton setImage: (someImage) forState: UIControlStateNormal];
You might want to also set this image for the other buttons states (highlighted, selected), it all depends on how you want the interface to behave.
It doesn't matter that it was assigned in Interface Builder. All you need to do is this:
[yourButtonName setImage:yourNewImageName forState:UIControlStateNormal];
You'll also likely want to set an image for
UIControlStateHighlighted
and possibly for
UIControlStateDisabled
and
UIControlStateSelected

When I set a UIButton's enabled property to NO, it automatically greys out the button (I'm using a picture for the button)

How do I make it so it doesn't grey out?
Set the same image for UIControlStateDisabled and UIControlStateNormal so the button does not generate the disabled state for you.