Search This Blog

Friday 4 May 2012

How to change title of button in Xcode

Hey friends,
Here is the code how to change the title of the UIButton:
In Your button action add the following code

-(IBAction)myButton:(UIButton *)sender{

NSString *str = (NSString *)[sender currentTitle];
if ([str isEqualToString:@"Play"]) 
{

[sender setTitle:[NSString stringWithString:@"Pause"] forState:UIControlStateNormal];[sender setImage:[UIImage imageNamed:@"Pause.png"] forState:UIControlStateHighlighted];
}
else
{

[sender setTitle:[NSString stringWithString:@"Play"forState:UIControlStateNormal];[sender setImage:[UIImage imageNamed:@"Play.png"] forState:UIControlStateNormal];


}

The explanation for the above code goes like, you must have seen in media player that while touching the Play button its text or image changes to pause the same thing can be achieved by the above code.

Good luck!!! :)

No comments:

Post a Comment