XandruCea XandruCea - 1 year ago 136
iOS Question

How can I add characters to an UILabel animated in iOS with Objective-C?

What I tried

I created a recursive function that loops over a

and ever time will go through this animation blog. This method is called by this code because I thought the problem why the animation on the
doesn't work is, that it is not run on the main thread.

[self performSelectorOnMainThread:@selector(writeText:)

The animation has a
block which also checks whether the animation is finished and then moves on to call the same function again. Furthermore I added an additional animation blog but nothing makes it able to add characters to the label smooth.

[UIView animateWithDuration:1.5f

//adding next character to text attribute of UILabel
} completion:^(BOOL finished) {

[UIView animateWithDuration:1.0f

if ( finished ){
[self performSelectorOnMainThread:@selector(writeText:)

} completion:nil];


What It looks like

enter image description here

What I found after my search wasn't right

I have been looking around for a while now and tried to find a question related to my problem but everything I found pointed only into one direction, changing the text of an
to another text, no single character

  • stackoverflow.com/questions/26402062/changing-the-text-of-a-uilabel-makes-it-reappear-when-using-uiviewkeyframeanimat

  • stackoverflow.com/questions/26703501/fade-between-text-in-a-uilabel-with-delay

Can Somebody help?

Answer Source

the setText method of a UILabel is not animatable. animateWithDuration:completion: will only animate change in frames, bounds, center, transform... See Apple docs on animation here for the list of animatable property : https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html

For your problem, you have to forget using animateWithDuration:completion: and create the animation yourself, by using a NSTimer for example for executing a addLetter: method every x seconds...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download