qg_java_17137
qg_java_17137

Reputation: 3569

When I set button title, there is fade-off and fade-out effect

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

Answers (3)

Piyush
Piyush

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

three-blocks
three-blocks

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

KKRocks
KKRocks

Reputation: 8322

Try this it is working in my code:

[UIView setAnimationsEnabled:NO];
[_cancleOrConfirmButton setTitle:@"Cancel" forState:UIControlStateNormal];
[UIView setAnimationsEnabled:YES];

Upvotes: 0

Related Questions