Sabbath Sabbath - 2 years ago 173
iOS Question

How to Animate uilabel text between 3 values

What I want is to animate my UILabel's text between 3 values repeatedly. The text I'd like to set is 'downloading.', 'downloading..', 'downloading...', and then, repeat. With this animation, I want to let my user know that the downloading is being done and the app is not stacked. I've been searching with google for a while and did not find a solution.

Any one can give me some reference about this? Thanks in advance.

Answer Source

Use the NStimer for changing the text

in .h file

@interface ViewController : UIViewController
    NSTimer * timer;
    UILabel * downloadingLbl;

and in .m file

- (void)viewDidLoad
    [super viewDidLoad];

    downloadingLbl.text = @"Downloading.";
    if (!timer) {
        timer = [NSTimer timerWithTimeInterval:0.5 target:self selector:@selector(onTick:) userInfo:nil repeats:YES];


    if ([downloadingLbl.text isEqualToString:@"Downloading."]) {
        downloadingLbl.text = @"Downloading..";
    } else if ([downloadingLbl.text isEqualToString:@"Downloading.."]) {
        downloadingLbl.text = @"Downloading...";
    } else if ([downloadingLbl.text isEqualToString:@"Downloading..."]) {
        downloadingLbl.text = @"Downloading.";

And when your download complete that make timer invalidate.

[timer invalidate];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download