Change the custom button by an other when the user click on it
I try to realize that, when the user click on a button (custom one), it will be changed by another button, to do so, i use the selected property :
What i notice that the image of the button is changed while the user keep pressing th开发者_JAVA百科e button, if he releases the button, it returns to his old form, what i need is it still changed sine the user select the button.
There is only one line of code.
[yourButton setBackgroundImage:[UIImage imageNamed:@"select-button.png"] forState:UIControlStateHighlighted];
This is best done programmatically, rather than in Interface Builder. Set up an action for your button such that when it is clicked, the button image changes:
- (IBAction)buttonTapped:(id)sender
{
UIButton *theButton = (UIButton *)sender;
if ([theButton currentImage] == self.imageOne) {
[theButton setImage:self.imageTwo forState:UIControlStateNormal];
}
else {
[theButton setImage:self.imageOne forState:UIControlStateNormal];
}
// (remaining action code)...
}
I think best way is Use two button in same frame ,When user click Button1,hide button1 and show button2.if user click button2,hide button2 and show button1
精彩评论