Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DennisBlah

macrumors 6502
Original poster
Dec 5, 2013
485
2
The Netherlands
Hey all, I'm trying to change some button title programaticly.
Just using
Code:
 [myButton setTitle: @"some new text" forState: UIControllStateNormal];

Actually I'm using an array with the new content, cus it will contain the next value of the current index. But that works.

Only thing is, once its doing that, it seems like its fading out, and back in with new title...

Anyone knows how to shut this animation off ?
 
Last edited:

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,563
6,062
Hey all, I'm trying to change some button title programaticly.
Just using
Code:
 [myButton setTitle: @"some new text"];

Actually I'm using an array with the new content, cus it will contain the next value of the current index. But that works.

Only thing is, once its doing that, it seems like its fading out, and back in with new title...

Anyone knows how to shut this animation off ?

You should use setTitle:forState:, I believe. Otherwise when the button changes state, the title will change back.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,563
6,062
This code should be giving you a compile-time error since UIButton has no setTitle: method. It does have setTitle:forState:.

Hm, it's also missing a title property. I could have sworn that it used to have that... was it perhaps removed from the documentation at some point, without actually being removed from the SDK?
 

DennisBlah

macrumors 6502
Original poster
Dec 5, 2013
485
2
The Netherlands
I know you also got the forState: parameter, else it wont build. I just didnt putted it in here.

My question is about:
Why does the setTitle, makes the button animate?
It fade's out and fade's back in with new title.

Howevery I'm doing the change before I unhide the view where the button sits in...
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Tried this one ?

Code:
+ (void)setAnimationsEnabled:(BOOL)enabled

That one should work.

DennisBlah, the default behavior for the new System button in iOS 7 is to animate the title change. In order to avoid that animation, try this:

Code:
[UIView setAnimationsEnabled:NO];
[myButton setTitle:@"some new text" forState:UIControlStateNormal];
[UIView setAnimationsEnabled:YES];
 

DennisBlah

macrumors 6502
Original poster
Dec 5, 2013
485
2
The Netherlands
That one should work.

DennisBlah, the default behavior for the new System button in iOS 7 is to animate the title change. In order to avoid that animation, try this:

Code:
[UIView setAnimationsEnabled:NO];
[myButton setTitle:@"some new text" forState:UIControlStateNormal];
[UIView setAnimationsEnabled:YES];



Ahhh I see, thats great!! It still has an little animation, but thats because you press a button has animation.
I'm glad the extra animation of changing title is gone now :)
I didnt putted it back to Yes cus its not needed at all :) Thanks a lot!
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
Ahhh I see, thats great!! It still has an little animation, but thats because you press a button has animation.
I'm glad the extra animation of changing title is gone now :)
I didnt putted it back to Yes cus its not needed at all :) Thanks a lot!

I would advise against setting animation to off globally and leaving it off. (by calling

Code:
[UIView setAnimationsEnabled: NO];

and then never calling

Code:
[UIView setAnimationsEnabled: YES];


You don't know what else that changes.

In fact I tried it, and it stopped a whole range of UIView animations, many of which could be triggered by the system. So you might screw up the functioning of other parts of your application.

Better to use code like this:

Code:
[UIView performWithoutAnimation: 
  ^{
    [aButton setTitle: @"new title" forState: UIControlStateNormal];
  }
];
 

DennisBlah

macrumors 6502
Original poster
Dec 5, 2013
485
2
The Netherlands
I would advise against setting animation to off globally and leaving it off. (by calling

Code:
[UIView setAnimationsEnabled: NO];

and then never calling

Code:
[UIView setAnimationsEnabled: YES];


You don't know what else that changes.

In fact I tried it, and it stopped a whole range of UIView animations, many of which could be triggered by the system. So you might screw up the functioning of other parts of your application.

Better to use code like this:

Code:
[UIView performWithoutAnimation: 
  ^{
    [aButton setTitle: @"new title" forState: UIControlStateNormal];
  }
];

Thanks for your reply. I understand what you mean by that. I will keep this in mind, but for that project there are no animations 'expected' anyways :)
So again, thanks I will keep this in mind :)
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
Thanks for your reply. I understand what you mean by that. I will keep this in mind, but for that project there are no animations 'expected' anyways :)
So again, thanks I will keep this in mind :)

You don't know what system methods are using UIView animation methods. Your navigation controllers might not draw correctly. Screen rotation animations might not draw correctly. Table view scrolling might not animate. Pushing an alert view might not work right. I don't know WHAT might malefaction, but SYSTEM behavior might change.

Do not set the flag to do not animate and leave it there. This is very likely to break something seemingly unrelated, and mark my words, you will quite likely regret it after spending countless hours weeks or months from now, trying to figure out why some XYZ isn't behaving correctly.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.