Reputation: 23
When I change the title of a UIButton it has this effect where the old title fades out and the new one fades in. Can I change the title without the animation?
[self.a setTitle:@"a" forState:UIControlStateNormal];
Upvotes: 0
Views: 472
Reputation: 9589
There is two way to do this
1.System Button without animation
- (IBAction)actionChangeButtonTitle:(id)sender
{
[UIView setAnimationsEnabled:NO];
[buttonTitleChange setTitle:@"title" forState:UIControlStateNormal];
[UIView setAnimationsEnabled:YES];
[buttonTitleChange layoutIfNeeded]; //For System Buttons
}
2.Custom Button Without animation
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn addTarget:self
action:@selector(actionChangeButtonTitle:)forControlEvents:UIControlEventTouchUpInside];
[btn setTitle:@"Change Title" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:btn];
- (IBAction)actionChangeButtonTitle:(id)sender
{
[btn setTitle:@"title" forState:UIControlStateNormal];
}
Thank You-:)
Upvotes: 0
Reputation: 10317
For system UIButton
, using:
[self.a layoutIfNeeded];
For custom UIButton
, using:
[UIView setAnimationsEnabled:NO];
[self.a setTitle:@"a" forState:UIControlStateNormal];
[UIView setAnimationsEnabled:YES];
Upvotes: 1