Reputation: 3569
When I use setTitle: forState:
method to set my button's title, there have the fade-out and fade-in effect.
- (void)respondsToTextField:(UITextField *)sender {
if ([sender.text isEqualToString:@""]) {
[_cancleOrConfirmButton setTitle:@"Cancel" forState:UIControlStateNormal];
}else {
[_cancleOrConfirmButton setTitle:@"Search" forState:UIControlStateNormal];
}
}
How to resolve it?
Upvotes: 1
Views: 107
Reputation: 1544
Try with it.
- (void)respondsToTextField:(UITextField *)sender {
if ([sender.text isEqualToString:@""]) {
[UIView performWithoutAnimation:^{
[_cancleOrConfirmButton setTitle:@"Cancel" forState:UIControlStateNormal];
[_cancleOrConfirmButton layoutIfNeeded];
}];
}else {
[UIView performWithoutAnimation:^{
[_cancleOrConfirmButton setTitle:@"Search" forState:UIControlStateNormal];
[_cancleOrConfirmButton layoutIfNeeded];
}];
}
}
Upvotes: 2
Reputation: 363
When You set the button title, if do not want the effect, you can set the titleLable.text
first.
Try this:
- (void)respondsToTextField:(UITextField *)sender {
if ([sender.text isEqualToString:@""]) {
_cancleOrConfirmButton.titleLabel.text = @"Cancel";
[_cancleOrConfirmButton setTitle:@"Cancel" forState:UIControlStateNormal];
}else {
_cancleOrConfirmButton.titleLabel.text = @"Search";
[_cancleOrConfirmButton setTitle:@"Search" forState:UIControlStateNormal];
}
}
Upvotes: 1
Reputation: 8322
Try this it is working in my code:
[UIView setAnimationsEnabled:NO];
[_cancleOrConfirmButton setTitle:@"Cancel" forState:UIControlStateNormal];
[UIView setAnimationsEnabled:YES];
Upvotes: 0